Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:cm.aptoide.pt.RemoteInTab.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == NEWREPO_FLAG) {
        if (data != null && data.hasExtra("update")) {
            final AlertDialog alrt = new AlertDialog.Builder(this).create();
            alrt.setTitle("Update repositories");
            alrt.setMessage("The list of repositories in use has been changed.\nDo you wish to update them?");
            alrt.setButton("Yes", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    updateRepos();//from ww w .ja va 2 s. c o  m
                }
            });
            alrt.setButton2("No", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    alrt.dismiss();
                }
            });
            alrt.show();
        }
    } else if (requestCode == SETTINGS_FLAG) {
        if (data != null && data.hasExtra("align")) {
            order_lst = data.getExtras().getString("align");
            prefEdit.putString("order_lst", order_lst);
            prefEdit.commit();
        }
    }
}

From source file:com.googlecode.android_scripting.facade.BluetoothFacade.java

@Rpc(description = "Connect to a device over Bluetooth. Blocks until the connection is established or fails.", returns = "True if the connection was established successfully.")
public String bluetoothConnect(
        @RpcParameter(name = "uuid", description = "The UUID passed here must match the UUID used by the server device.") @RpcDefault(DEFAULT_UUID) String uuid,
        @RpcParameter(name = "address", description = "The user will be presented with a list of discovered devices to choose from if an address is not provided.") @RpcOptional String address)
        throws IOException {
    if (address == null) {
        Intent deviceChooserIntent = new Intent();
        deviceChooserIntent.setComponent(Constants.BLUETOOTH_DEVICE_LIST_COMPONENT_NAME);
        Intent result = mAndroidFacade.startActivityForResult(deviceChooserIntent);
        if (result != null && result.hasExtra(Constants.EXTRA_DEVICE_ADDRESS)) {
            address = result.getStringExtra(Constants.EXTRA_DEVICE_ADDRESS);
        } else {// w  ww  .  j a  v a2s .c o  m
            return null;
        }
    }
    BluetoothDevice mDevice;
    BluetoothSocket mSocket;
    BluetoothConnection conn;
    mDevice = mBluetoothAdapter.getRemoteDevice(address);
    mSocket = mDevice.createRfcommSocketToServiceRecord(UUID.fromString(uuid));
    // Always cancel discovery because it will slow down a connection.
    mBluetoothAdapter.cancelDiscovery();
    mSocket.connect();
    conn = new BluetoothConnection(mSocket);
    return addConnection(conn);
}

From source file:net.openwatch.acluaz.FormFragmentActivity.java

@Override
public void onPause() {
    Log.i(TAG, "onPause");
    Intent i = this.getIntent();
    // If we did not submit the form AND this is a new report (not saved in database)
    // save the incident form to prefs
    if (!did_submit && !i.hasExtra(Constants.INTERNAL_DB_ID)) {
        // save incident prefs
        FormFragment incidentFrag = this.getIncidentFormFragment();
        try {/*from   w  w w. ja  v a  2 s .  co  m*/
            incidentFrag.writeJsonToPrefs(Constants.INCIDENT_PREFS, incidentFrag.toJson(
                    (ViewGroup) incidentFrag.getView().findViewById(R.id.incident_form_container), null));
        } catch (NullPointerException e) {
        }
    }
    super.onPause();

}

From source file:com.ratebeer.android.gui.components.PosterService.java

private void callbackMessenger(Intent intent, int result) {
    if (intent.hasExtra(EXTRA_MESSENGER)) {
        // Prepare a message
        Messenger callback = intent.getParcelableExtra(EXTRA_MESSENGER);
        Message msg = Message.obtain();/*from   w  ww  . jav  a2  s.c  o m*/
        msg.arg1 = result;
        try {
            // Send it back to the messenger, i.e. the activity
            callback.send(msg);
        } catch (RemoteException e) {
            Log.e(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME,
                    "Cannot call back to activity to deliver message '" + msg.toString() + "'");
        }
    }
}

From source file:edgargtzg.popularmovies.MovieDetailsFragment.java

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

    // The detail Activity called via intent.  Inspect the intent for movie data.
    Intent intent = getActivity().getIntent();
    if (intent != null && intent.hasExtra(MovieItem.class.getCanonicalName())) {
        Bundle movieData = intent.getExtras();
        mMovieItem = movieData.getParcelable(MovieItem.class.getCanonicalName());

        if (mMovieItem != null) {

            // The MovieItemVideoAdapter will take data from a source and
            // use it to populate the list it's attached to.
            mMovieVideoAdapter = new MovieItemVideoAdapter(getActivity(), // The current context (this activity)
                    R.layout.list_video_movie_item, new ArrayList<MovieItemVideo>());

            // The MovieItemReviewAdapter will take data from a source and
            // use it to populate the list it's attached to.
            mMovieReviewAdapter = new MovieItemReviewAdapter(getActivity(), // The current context (this activity)
                    R.layout.list_review_movie_item, new ArrayList<MovieItemReview>());

            if (savedInstanceState != null) {
                mListOfVideos = (ArrayList<MovieItemVideo>) savedInstanceState.get(VIDEO_LIST_KEY);
                if (mListOfVideos != null) {
                    mMovieVideoAdapter.addAll(mListOfVideos);
                }//from ww w . j a v a2s  .c  o  m
                mListOfReviews = (ArrayList<MovieItemReview>) savedInstanceState.get(REVIEW_LIST_KEY);
                if (mListOfReviews != null) {
                    mMovieReviewAdapter.addAll(mListOfReviews);
                }
            } else {
                mListOfVideos = new ArrayList<>();
                mListOfReviews = new ArrayList<>();
                updateMovieData(mMovieItem);
            }
        }
    }
}

From source file:com.concentricsky.android.khanacademy.data.KADataService.java

/**
 * Used for long-running operations including library updates and video downloads.
 * //  www .  ja v  a  2s .  c o  m
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("KADataService", "Received start id " + startId + ": " + intent);

    PendingIntent pendingIntent = null;
    if (intent.hasExtra(Intent.EXTRA_INTENT)) {
        // TODO : use this intent. It needs to be called with the results of requestLibraryUpdate (so far)
        pendingIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    }

    if (ACTION_LIBRARY_UPDATE.equals(intent.getAction())) {
        requestLibraryUpdate(startId, pendingIntent, intent.getBooleanExtra(EXTRA_FORCE, false));
        return START_REDELIVER_INTENT;
    }

    if (ACTION_UPDATE_DOWNLOAD_STATUS.equals(intent.getAction())) {
        Log.d(LOG_TAG, "update download status");
        updateDownloadStatus(intent, pendingIntent, startId);
        return START_REDELIVER_INTENT;
    }

    /*
    START_NOT_STICKY
    Do not recreate the service, unless there are pending intents to deliver. This is the 
    safest option to avoid running your service when not necessary and when your application 
    can simply restart any unfinished jobs.
    START_STICKY
    Recreate the service and call onStartCommand(), but do not redeliver the last intent. 
    Instead, the system calls onStartCommand() with a null intent, unless there were pending 
    intents to start the service, in which case, those intents are delivered. This is suitable 
    for media players (or similar services) that are not executing commands, but running 
    indefinitely and waiting for a job.
    START_REDELIVER_INTENT
    Recreate the service and call onStartCommand() with the last intent that was delivered 
    to the service. Any pending intents are delivered in turn. This is suitable for services 
    that are actively performing a job that should be immediately resumed, such as downloading a file.
     */

    // If we reach this point, the intent has some unknown action, so just ignore it and stop.
    this.stopSelfResult(startId);
    return START_NOT_STICKY;
}

From source file:com.pushwoosh.plugin.pushnotifications.PushNotifications.java

private void checkMessage(Intent intent) {
    if (null != intent) {
        if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT)) {
            doOnMessageReceive(intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT));
        } else if (intent.hasExtra(PushManager.REGISTER_EVENT)) {
            doOnRegistered(intent.getExtras().getString(PushManager.REGISTER_EVENT));
        } else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) {
            doOnUnregistered(intent.getExtras().getString(PushManager.UNREGISTER_EVENT));
        } else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) {
            doOnRegisteredError(intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT));
        } else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) {
            doOnUnregisteredError(intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT));
        }/*w  w  w. j  a  v  a 2s. co m*/

        intent.removeExtra(PushManager.PUSH_RECEIVE_EVENT);
        intent.removeExtra(PushManager.REGISTER_EVENT);
        intent.removeExtra(PushManager.UNREGISTER_EVENT);
        intent.removeExtra(PushManager.REGISTER_ERROR_EVENT);
        intent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT);

        cordova.getActivity().setIntent(intent);
    }
}

From source file:com.putlocker.upload.DownloadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    PutlockerUpDownloadJob upDownJob = null;
    Notification notification = null;

    if (intent.hasExtra(JOB_EXTRA_DOWNLOAD)) {
        final PutlockerDownloadJob job = intent.getParcelableExtra(JOB_EXTRA_DOWNLOAD);
        notification = createDownloadNotification(job, this, 0);
        upDownJob = job;/*from  ww w.j av a 2s .  c  o  m*/
    } else {
        final PutlockerUploadJob job = intent.getParcelableExtra(JOB_EXTRA_UPLOAD);
        notification = createDownloadNotification(job, this, 0);
        upDownJob = job;
    }

    if (downloadJobs.size() == 0) {
        startForeground((int) upDownJob.getGlobalId(), notification);
    } else {
        mNM.notify(upDownJob.getGlobalId(), notification);
    }

    downloadJobs.append(upDownJob.getGlobalId(), notification);

    return super.onStartCommand(intent, flags, startId);
}

From source file:babbq.com.searchplace.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    if (intent.hasExtra(SearchManager.QUERY)) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (!TextUtils.isEmpty(query)) {
            searchView.setQuery(query, false);
            searchFor(query);/*from   w  w w.  j a va2s.c om*/
        }
    }
}

From source file:com.nexmo.sdk.verify.client.VerifyClient.java

/**
 * Handle the GCM notifications broadcast receiver, enable it to automatically trigger the check request
 * for the ongoing verify.//from  w w  w  . j  av  a 2 s  .c  o  m
 */
private void setGcmBroadcastReceiver() {
    this.gcmPayloadBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.hasExtra(VerifyGcmListenerService.MESSAGE_KEY_PIN)) {
                String pinCode = intent.getExtras().getString(VerifyGcmListenerService.MESSAGE_KEY_PIN);
                Log.d(TAG, "gcmPayloadBroadcastReceiver Pin: " + pinCode);
                manageCheckPin(pinCode);
            }
        }
    };

    LocalBroadcastManager.getInstance(this.nexmoClient.getContext()).registerReceiver(
            this.gcmPayloadBroadcastReceiver, new IntentFilter(VerifyGcmListenerService.ACTION_BROADCAST_PIN));
}