Example usage for android.content Intent getLongExtra

List of usage examples for android.content Intent getLongExtra

Introduction

In this page you can find the example usage for android.content Intent getLongExtra.

Prototype

public long getLongExtra(String name, long defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:edu.mit.media.funf.probe.Probe.java

/**
 * Send some values to each requesting pending intent
 * @param valuesIntent/*from  w ww  .  j a v a2  s.c om*/
 */
protected void _callback_registered(Intent valuesIntent, PendingIntent callback) {
    long epochTimestamp = valuesIntent.getLongExtra(TIMESTAMP, 0L);
    Set<PendingIntent> callbacks = new HashSet<PendingIntent>();
    if (callback != null) {
        callbacks.add(callback);
    }
    ArrayList<Intent> requests = null;
    if (requestsIntent != null) {
        requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY);
    }

    if (ACTION_DATA.equals(valuesIntent.getAction())) {
        // Send to all requesters
        if (requests != null && !requests.isEmpty()) {
            JSONObject dataSentTimes = null;
            try {
                dataSentTimes = new JSONObject(
                        getHistoryPrefs().getString(MOST_RECENT_DATA_BY_REQUEST_KEY, "{}"));
            } catch (JSONException e) {
                Log.e(TAG, "Unable to parse data sent history.");
                dataSentTimes = new JSONObject();
            }

            Parameter[] availableParameters = getAvailableParameters();
            for (Intent request : requests) {
                PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY);
                ArrayList<Bundle> dataRequests = Utils.getArrayList(request.getExtras(), REQUESTS_KEY);

                for (Bundle dataRequest : dataRequests) {
                    String requestKey = normalizedStringRepresentation(dataRequest, getAvailableParameters());
                    long lastDataSentTime = dataSentTimes.optLong(requestKey);
                    // TODO: If data request accepts passive data, but also needs data enforced on a schedule
                    // we may need to make logic more complicated
                    if (isDataRequestSatisfied(dataRequest, availableParameters, epochTimestamp,
                            lastDataSentTime)
                            || isDataRequestAcceptingPassiveData(dataRequest, availableParameters)) {
                        callbacks.add(requesterCallback);
                        try {
                            dataSentTimes.put(requestKey, epochTimestamp);
                        } catch (JSONException e) {
                            Log.e(TAG, "Unable to store data sent time in .");
                        }
                    }
                }
            }

            // Save the data sent times
            getHistoryPrefs().edit().putString(MOST_RECENT_DATA_BY_REQUEST_KEY, dataSentTimes.toString())
                    .putLong(MOST_RECENT_DATA_KEY, epochTimestamp).commit();
        }

    } else {
        // Add all
        for (Intent request : requests) {
            PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY);
            callbacks.add(requesterCallback);
        }
    }

    Log.d(TAG, "Sent probe data at " + epochTimestamp);
    for (PendingIntent requesterCallback : callbacks) {
        try {
            requesterCallback.send(this, 0, valuesIntent);
        } catch (CanceledException e) {
            Log.w(TAG, "Unable to send to canceled pending intent at " + epochTimestamp);
            Map<PendingIntent, Intent> callbacksToRequests = getCallbacksToRequests(requests);
            Intent request = callbacksToRequests.get(requesterCallback);
            if (request != null) {
                deadRequests.add(request);
            }
        }
    }

    updateRequests();
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.activities.MainActivity.java

/**
 * ActivityResults will usually be coming from either the detail activity's find on map button.
 * the//www.  j a  va 2s.c  om
 *
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    VPParentFragment fragmentParent = (VPParentFragment) getSupportFragmentManager()
            .findFragmentById(R.id.main_frg_body);

    switch (requestCode) {
    case RHCareerFairLayout.REQUEST_CODE_FIND_ON_MAP:
        if (resultCode == RESULT_OK) {
            // Go to Layout fragment.
            fragmentParent.getPager().setCurrentItem(0);

            // Check if current fragment is Layout fragment
            Fragment fragment = fragmentParent.getCurrentFragment();
            if (fragment instanceof VPLayoutContainerFragment) {
                VPLayoutContainerFragment mapFragment = (VPLayoutContainerFragment) fragment;
                long companyId = data.getLongExtra(RHCareerFairLayout.INTENT_KEY_SELECTED_COMPANY, -1);
                if (companyId == -1) {
                    throw new IllegalStateException("Invalid companyId provided back to map.");
                }
                mapFragment.flashCompany(companyId);
            }
        }
        break;
    //            case 1234:
    //                if (resultCode == RESULT_OK) {
    //                    ArrayList<String> matches = data
    //                            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    //                    search.populateEditText(matches);
    //                }
    //                super.onActivityResult(requestCode, resultCode, data);
    default:
        break;
    }
}

From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    acquireCpuWakeLock();//from w  w w  . ja v  a  2  s .c o m

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    km.inKeyguardRestrictedInputMode();
    if (km.inKeyguardRestrictedInputMode()) {
        Log.i(TAG, " ??");
        isKeyguardRestrictedInputMode = true;
    } else {
        Log.i(TAG, "   ??");
    }

    mLastNetworkStatus = NetworkUtils.isConnected(this);
    Intent intent = getIntent();
    if (intent == null || !PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "empty or none broadcast intent value ...");
        finishActivity();
        return;
    }

    mBroadcastData = intent.getParcelableExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA);
    if (mBroadcastData == null) {
        Log.d(TAG, ">> payload data is null");
        finishActivity();
        return;
    }

    mBroadcastPayloadIdx = intent.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1);
    Log.d(TAG, ">> onCreate() mBroadcastPayloadIdx= " + mBroadcastPayloadIdx);

    // ? ms  ? ?? ? ?   ?  ????
    // broadcast ? .
    //  ?? ?? ??.
    Intent i = new Intent(this, RealtimeBroadcastActivity.class);
    i.setAction(intent.getAction());
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, mBroadcastData);
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, mBroadcastPayloadIdx);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);

    IntentFilter filter = new IntentFilter();
    filter.addAction(PushConstants.ACTION_PUSH_MESSAGE_RECEIVED);
    filter.addAction(Constants.ACTION_BROWSER_ACTIVITY_CLOSE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mBroadcastReceiver, intentFilter);

    hideSystemUI();
    /*
    final Window win = getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
    */

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        setContentView(R.layout.fragment_text_broadcast);
    } else {
        setContentView(R.layout.fragment_audio_broadcast);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        mcheckText2SpeechLister = this;
        // ?
        mTextView = (TextView) findViewById(R.id.broadcast_text);
        mTextView.setText(mBroadcastData.getMessage());
        mTextView.setVerticalScrollBarEnabled(true);
        mTextView.setHorizontalScrollBarEnabled(false);
        mTextView.setMovementMethod(new ScrollingMovementMethod());

        mHandler.sendEmptyMessageDelayed(HANDLER_MESSAGE_SETUP_CURRENT_PLAYING, 800);
        Log.d(TAG, "text broadcast = " + mBroadcastData.getMessage());

        mText2SpeechHandler = new TextToSpeechHandler(this, this);
        checkText2SpeechAvailable();
        mIsTTS = true;
    } else {
        // , ??
        mWebView = (WebView) findViewById(R.id.webview);
        mWebViewClient = new RealtimeBroadcastWebViewClient(this, mWebView, this);
        mWebViewClient.setBackgroundTransparent();

        String url = mBroadcastData.getMessage();
        if (url.indexOf("?") > 0) {
            if (!url.contains("UUID=")) {
                url += ("&UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                url += ("&APPID=" + getApplicationContext().getPackageName());
            }
        } else {
            if (!url.contains("UUID=")) {
                url += ("?UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                if (!url.contains("UUID=")) {
                    url += ("?APPID=" + getApplicationContext().getPackageName());
                } else {
                    url += ("&APPID=" + getApplicationContext().getPackageName());
                }
            }
        }

        mWebViewClient.loadUrl(url);
        mIsTTS = false;
    }
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mStreamMusicVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
            AudioManager.FLAG_PLAY_SOUND);

    if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) {
        StateListener phoneStateListener = new StateListener();
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

From source file:com.lambdasoup.quickfit.alarm.AlarmService.java

@Override
@WorkerThread/*from w w w .  j  av a 2s  .c  om*/
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_ON_ALARM_RECEIVED.equals(action)) {
            handleOnAlarmReceived(intent);
        } else if (ACTION_ON_TIME_CHANGED.equals(action)) {
            handleOnTimeChanged(intent);
        } else if (ACTION_ON_NEXT_OCC_CHANGED.equals(action)) {
            handleOnNextOccChanged();
        } else if (ACTION_ON_NOTIFICATIONS_CANCELED.equals(action)) {
            long[] scheduleIds = intent.getLongArrayExtra(EXTRA_SCHEDULE_IDS);
            handleOnNotificationsCanceled(scheduleIds);
        } else if (ACTION_ON_DID_IT.equals(action)) {
            long scheduleId = intent.getLongExtra(EXTRA_SCHEDULE_ID, -1);
            long workoutId = intent.getLongExtra(EXTRA_WORKOUT_ID, -1);
            handleOnDidIt(scheduleId, workoutId);
        } else if (ACTION_ON_SNOOZE.equals(action)) {
            long scheduleId = intent.getLongExtra(EXTRA_SCHEDULE_ID, -1);
            handleOnSnooze(scheduleId);
        } else {
            throw new IllegalArgumentException("Unexpected action " + action);
        }
    }
}

From source file:org.totschnig.myexpenses.fragment.TransactionList.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == ProtectedFragmentActivity.FILTER_CATEGORY_REQUEST
            && resultCode != Activity.RESULT_CANCELED) {
        String label = intent.getStringExtra(KEY_LABEL);
        if (resultCode == Activity.RESULT_OK) {
            long catId = intent.getLongExtra(KEY_CATID, 0);
            addFilterCriteria(R.id.FILTER_CATEGORY_COMMAND, new CategoryCriteria(label, catId));
        }/* w  ww. j av  a 2 s . c  o m*/
        if (resultCode == Activity.RESULT_FIRST_USER) {
            long[] catIds = intent.getLongArrayExtra(KEY_CATID);
            addFilterCriteria(R.id.FILTER_CATEGORY_COMMAND, new CategoryCriteria(label, catIds));
        }
    }
}

From source file:ru.neverdark.phototools.fragments.SunsetFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.message("Enter");
    if (requestCode == Constants.LOCATION_POINT_ON_MAP_CHOICE) {
        if (resultCode == Activity.RESULT_OK) {
            mLatitude = data.getDoubleExtra(Constants.LOCATION_LATITUDE, 0.0);
            mLongitude = data.getDoubleExtra(Constants.LOCATION_LONGITUDE, 0.0);
            mLocationName = data.getStringExtra(Constants.LOCATION_NAME);
            mSelectionId = data.getLongExtra(Constants.LOCATION_RECORD_ID,
                    Constants.LOCATION_POINT_ON_MAP_CHOICE);

            getTimeZoneFromGoogle();/*w  w w  .j  a v  a2  s .c om*/

            setTextLocation();
        }
    }
}

From source file:io.oceanos.shaderbox.ShaderEditorActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final LayoutInflater inflater = getLayoutInflater();
    final View customActionBarView = inflater.inflate(R.layout.actionbar_view_save, null);
    final View shaderActionView = customActionBarView.findViewById(R.id.actionbar_view);
    final View shaderActionSave = customActionBarView.findViewById(R.id.actionbar_save);
    shaderActionView.setOnClickListener(new View.OnClickListener() {
        @Override/*from   www .ja va 2  s  . c  om*/
        public void onClick(View v) {
            if (result.isSuccess())
                onView(shader);
            else {
                Toast errorMsg = Toast.makeText(getBaseContext(), result.getError(), Toast.LENGTH_LONG);
                errorMsg.getView().setBackgroundColor(getResources().getColor(R.color.editor_color_error));
                errorMsg.show();
            }
        }
    });
    shaderActionSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSave(shader);
        }
    });

    fps = (TextView) customActionBarView.findViewById(R.id.text_fps);
    viewError = (TextView) shaderActionView.findViewById(R.id.viewError);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(R.layout.activity_editor);

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    ShaderDatabase database = new ShaderDatabase(getBaseContext());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            long id = database.newShader();
            Cursor cursor = database.findById(id);
            if (cursor.moveToFirst())
                shader = Shader.getValues(cursor);
            cursor.close();
            if (sharedText != null)
                shader.setText(sharedText);
            else
                shader.setText("");
        }
    } else {
        long id = intent.getLongExtra("ID", 0);
        Cursor cursor = database.findById(id);
        if (cursor.moveToFirst())
            shader = Shader.getValues(cursor);
        cursor.close();
    }
    database.close();

    setSymbolListener(R.id.action_tab, '\t');
    setSymbolListener(R.id.action_rpo, '(');
    setSymbolListener(R.id.action_rpc, ')');
    setSymbolListener(R.id.action_cpo, '{');
    setSymbolListener(R.id.action_cpc, '}');
    setSymbolListener(R.id.action_dotcoma, ';');
    setSymbolListener(R.id.action_coma, ',');
    setSymbolListener(R.id.action_dot, '.');
    setSymbolListener(R.id.action_plus, '+');
    setSymbolListener(R.id.action_minus, '-');
    setSymbolListener(R.id.action_times, '*');
    setSymbolListener(R.id.action_div, '/');
    setSymbolListener(R.id.action_equal, '=');
    setSymbolListener(R.id.action_spo, '[');
    setSymbolListener(R.id.action_spc, ']');
    setSymbolListener(R.id.action_and, '&');
    setSymbolListener(R.id.action_or, '|');
    setSymbolListener(R.id.action_greater, '>');
    setSymbolListener(R.id.action_lesser, '<');
    setSymbolListener(R.id.action_cardinal, '#');

    final Handler uiHandler = new Handler(this);
    renderer = new ShaderRenderer(shader, uiHandler);

    shaderView = (ShaderGLView) findViewById(R.id.shader_view);
    shaderView.setRenderer(renderer);
    shaderView.setVRModeEnabled(false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int textSize = Integer.parseInt(prefs.getString("pref_editor_text_size", "14"));
    int opacity = Integer.parseInt(prefs.getString("pref_editor_opacity", "127"));
    editor = (ShaderEditor) findViewById(R.id.editor);
    editor.setTextSize(textSize);
    editor.setBackgroundColor(opacity << 24);
    editor.setHorizontallyScrolling(true);
    editor.setHorizontalScrollBarEnabled(true);

    editor.setText(shader.getText());

    ScrollView scroll = (ScrollView) findViewById(R.id.scroll);
    editor.setScrollView(scroll);

    compileRT = prefs.getBoolean("pref_compile_rt", true);
}

From source file:de.ub0r.android.smsdroid.MessageListActivity.java

/**
 * Parse data pushed by {@link Intent}./*from  ww  w. ja  va  2  s .  c om*/
 * 
 * @param intent
 *            {@link Intent}
 */
private void parseIntent(final Intent intent) {
    Log.d(TAG, "parseIntent(" + intent + ")");
    if (intent == null) {
        return;
    }
    Log.d(TAG, "got action: " + intent.getAction());
    Log.d(TAG, "got uri: " + intent.getData());

    this.needContactUpdate = true;

    this.uri = intent.getData();
    if (this.uri != null) {
        if (!this.uri.toString().startsWith(URI)) {
            this.uri = Uri.parse(URI + this.uri.getLastPathSegment());
        }
    } else {
        final long tid = intent.getLongExtra("thread_id", -1L);
        this.uri = Uri.parse(URI + tid);
        if (tid < 0L) {
            try {
                this.startActivity(ConversationListActivity.getComposeIntent(this, null));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
            }
            this.finish();
            return;
        }
    }

    final int threadId = Integer.parseInt(this.uri.getLastPathSegment());
    final Conversation c = Conversation.getConversation(this, threadId, true);
    this.conv = c;

    if (c == null) {
        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }

    final Contact contact = c.getContact();
    contact.update(this, false, true);

    Log.d(TAG, "address: " + contact.getNumber());
    Log.d(TAG, "name: " + contact.getName());
    Log.d(TAG, "displayName: " + contact.getDisplayName());

    final ListView lv = this.getListView();
    lv.setStackFromBottom(true);

    MessageAdapter adapter = new MessageAdapter(this, this.uri);
    this.setListAdapter(adapter);

    String displayName = contact.getDisplayName();
    this.setTitle(displayName);
    String number = contact.getNumber();
    if (displayName.equals(number)) {
        this.getSupportActionBar().setSubtitle(null);
    } else {
        this.getSupportActionBar().setSubtitle(number);
    }

    this.setContactIcon(contact);

    final String body = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (!TextUtils.isEmpty(body)) {
        this.etText.setText(body);
    }

    this.setRead();
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case PHOTO:/*from w  w  w. j ava2 s  .c om*/
        if (resultCode == RESULT_OK) {
            getPhoto(data.getData());
        }
        break;
    case TAGS:
        if ((resultCode == RESULT_OK) && data.hasExtra(Stags) && data.hasExtra(Accounts.SID))
            mAccountsTags.put(data.getLongExtra(Accounts.SID, Sonet.INVALID_ACCOUNT_ID),
                    data.getStringArrayExtra(Stags));
        break;
    }
}

From source file:com.newcell.calltext.ui.account.AccountsEditListFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) {

        if (requestCode == CHOOSE_WIZARD) {
            // Wizard has been chosen, now create an account
            String wizardId = data.getStringExtra(WizardUtils.ID);
            Toast.makeText(getActivity(), "wizardId::" + wizardId, Toast.LENGTH_LONG).show();
            if (wizardId != null) {
                showDetails(SipProfile.INVALID_ID, wizardId);
            }// ww  w  .  j  ava 2s .c  om
        } else if (requestCode == CHANGE_WIZARD) {
            // Change wizard done for this account.
            String wizardId = data.getStringExtra(WizardUtils.ID);
            long accountId = data.getLongExtra(Intent.EXTRA_UID, SipProfile.INVALID_ID);

            if (wizardId != null && accountId != SipProfile.INVALID_ID) {
                ContentValues cv = new ContentValues();
                cv.put(SipProfile.FIELD_WIZARD, wizardId);
                getActivity().getContentResolver().update(
                        ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, accountId), cv, null, null);

            }

        }
    }

}