Example usage for android.content Intent putExtras

List of usage examples for android.content Intent putExtras

Introduction

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

Prototype

public @NonNull Intent putExtras(@NonNull Bundle extras) 

Source Link

Document

Add a set of extended data to the intent.

Usage

From source file:com.test.onesignal.GenerateNotificationRunner.java

private NotificationExtenderServiceTestBase startNotificationExtender(Bundle bundlePayload,
        Class serviceClass) {//from   w w  w  .j  a  v  a  2  s . c om
    ServiceController<NotificationExtenderServiceTestBase> controller = Robolectric.buildService(serviceClass);
    NotificationExtenderServiceTestBase service = controller.attach().create().get();
    Intent testIntent = new Intent(RuntimeEnvironment.application,
            NotificationExtenderServiceTestReturnFalse.class);
    testIntent.putExtras(bundlePayload);
    controller.withIntent(testIntent).startCommand(0, 0);

    return service;
}

From source file:com.dwdesign.tweetings.activity.DraftsActivity.java

private void composeDraft(final DraftItem draft) {
    final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
    final Bundle bundle = new Bundle();
    final Uri image_uri = draft.media_uri == null ? null : Uri.parse(draft.media_uri);
    bundle.putString(INTENT_KEY_TEXT, draft.text);
    bundle.putLongArray(INTENT_KEY_IDS, draft.account_ids);
    bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, draft.in_reply_to_status_id);
    bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, draft.in_reply_to_name);
    bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, draft.in_reply_to_screen_name);
    bundle.putParcelable(INTENT_KEY_IMAGE_URI, image_uri);
    bundle.putBoolean(INTENT_KEY_IS_IMAGE_ATTACHED, draft.is_image_attached);
    bundle.putBoolean(INTENT_KEY_IS_PHOTO_ATTACHED, draft.is_photo_attached);
    bundle.putBoolean(INTENT_KEY_IS_QUOTE, draft.is_quote);
    intent.putExtras(bundle);
    mResolver.delete(Drafts.CONTENT_URI, Drafts._ID + " = " + draft._id, null);
    startActivityForResult(intent, REQUEST_COMPOSE);
}

From source file:io.teak.sdk.Teak.java

@Override
public void onReceive(Context inContext, Intent intent) {
    final Context context = inContext.getApplicationContext();

    if (!Teak.isEnabled()) {
        Log.e(LOG_TAG, "Teak is disabled, ignoring onReceive().");
        return;/*w ww  .j  a  va  2s. c  o m*/
    }

    String action = intent.getAction();

    if (GCM_RECEIVE_INTENT_ACTION.equals(action)) {
        final TeakNotification notif = TeakNotification.remoteNotificationFromIntent(context, intent);
        if (notif == null) {
            return;
        }

        // Send Notification Received Metric
        Session.whenUserIdIsReadyRun(new Session.SessionRunnable() {
            @Override
            public void run(Session session) {
                HashMap<String, Object> payload = new HashMap<>();
                payload.put("app_id", session.appConfiguration.appId);
                payload.put("user_id", session.userId());
                payload.put("platform_id", notif.teakNotifId);

                new Request("/notification_received", payload, session).run();
            }
        });
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();

        // Cancel any updates pending
        TeakNotification.cancel(context, bundle.getInt("platformId"));

        // Launch the app
        if (!bundle.getBoolean("noAutolaunch")) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG,
                        "Notification (" + bundle.getString("teakNotifId") + ") opened, auto-launching app.");
            }
            Intent launchIntent = context.getPackageManager()
                    .getLaunchIntentForPackage(context.getPackageName());
            launchIntent.addCategory("android.intent.category.LAUNCHER");
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            launchIntent.putExtras(bundle);
            if (bundle.getString("deepLink") != null) {
                launchIntent.setData(Uri.parse(bundle.getString("deepLink")));
            }
            context.startActivity(launchIntent);
        } else {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId")
                        + ") opened, NOT auto-launching app (noAutoLaunch flag present, and set to true).");
            }
        }

        // Send broadcast
        if (Teak.localBroadcastManager != null) {
            Intent broadcastEvent = new Intent(TeakNotification.LAUNCHED_FROM_NOTIFICATION_INTENT);
            broadcastEvent.putExtras(bundle);
            Teak.localBroadcastManager.sendBroadcast(broadcastEvent);
        }
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();
        TeakNotification.cancel(context, bundle.getInt("platformId"));
    }

}

From source file:com.adamas.client.android.MainActivity.java

private void processQrCodeText(String content) {
    if (content != null && content.trim().length() == 32) {
        //Connector key
        content = content.trim();// w  w w. ja  v a 2s  . co m
        SharedPreferences sharedPref = getSharedPreferences(Store.STORE_ADAMAS_CONNECTORS,
                Context.MODE_PRIVATE);
        Store.saveConnectorKey(sharedPref, Converter.hexToBytes(content));
        toast(getString(R.string.toast_connector_key_saved), ToastType.info);
    } else if (content != null && content.trim().length() > 0) {
        Connector connector = Connector.parseStringFromQrCode(content);
        if (connector == null) {
            //maybe it is encrypted, let's decrypt it
            SharedPreferences sharedPref = getSharedPreferences(Store.STORE_ADAMAS_CONNECTORS,
                    Context.MODE_PRIVATE);
            List<byte[]> keys = Store.loadConnectorKeys(sharedPref);
            byte[] bytes = Converter.hexToBytes(content.trim());
            for (byte[] key : keys) {
                byte[] decrypted = CryptUtil.decrypt(key, bytes);
                if (decrypted != null) {
                    connector = Connector.parseStringFromQrCode(new String(decrypted));
                    if (connector != null) {
                        break;
                    }
                }
            }
        }
        if (connector != null) {
            Intent importIntent = new Intent(this, ImportConnectorActivity.class);
            Bundle mBundle = new Bundle();
            mBundle.putSerializable(ImportConnectorActivity.ADAMAS_CONNECTOR, connector);
            importIntent.putExtras(mBundle);
            startActivityForResult(importIntent, IMPORT_CONNECTOR_REQUEST_CODE);
        }
    }
}

From source file:com.bonsai.wallet32.SendBitcoinActivity.java

public void onSendBitcoin(int acctId, String addrString, long amount, long fee) {

    try {//from  w  w w.j a v  a 2  s . c  om
        mLogger.info(String.format("send from %d, to %s, amount %s, fee %s starting", acctId, addrString,
                mBTCFmt.format(amount), mBTCFmt.format(fee)));

        mWalletService.sendCoinsFromAccount(acctId, addrString, amount, fee, spendUnconfirmed());

        mLogger.info("send finished");

        // Head to the transaction view for this account ...
        Intent intent = new Intent(this, ViewTransactionsActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("accountId", mCheckedFromId);
        intent.putExtras(bundle);
        startActivity(intent);

        // We're done here ...
        finish();

    } catch (RuntimeException ex) {
        mLogger.error(ex.toString());
        showErrorDialog(ex.getMessage());
        return;
    }
}

From source file:com.group7.dragonwars.GameActivity.java

public final void endGame() {
    setContentView(R.layout.loading_screen);
    Intent intent = new Intent(this, Results.class);
    Bundle b = new Bundle();
    b.putString("winnerName", state.getWinner().getName());
    b.putInt("turns", state.getTurns());
    Statistics stats = state.getStatistics();
    Double damageDealt = stats.getStatistic("Damage dealt");
    Double damageReceived = stats.getStatistic("Damage received");
    Double distanceTravelled = stats.getStatistic("Distance travelled");
    Integer goldCollected = stats.getStatistic("Gold received").intValue();
    Integer unitsKilled = stats.getStatistic("Units killed").intValue();
    Integer unitsMade = stats.getStatistic("Units produced").intValue();

    Database db = new Database(getApplicationContext());
    db.AddEntry(damageDealt, damageReceived, distanceTravelled, goldCollected, unitsKilled, unitsMade);
    db.Close();/*from   ww  w  . j a va  2s. c  om*/

    for (Map.Entry<String, Double> ent : stats.getEntrySet()) {
        b.putDouble(ent.getKey(), ent.getValue().doubleValue());
    }

    intent.putExtras(b);
    startActivity(intent);
    finish();
}

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
protected void onDestroy() {
    // System is destroying activity for no apparent reason...
    // Since we haven't saved state nor called finish we'll restart ourselves
    // https://android.googlesource.com/platform/frameworks/base/+/f83c555d8a153662d067702c0df5761b5e71b1bf%5E%21/services/java/com/android/server/am/ActivityManagerService.java
    if (!mDestroyExpected && getCallingActivity() == null && // Not started for result
            sLastForceFinish + 3000 < SystemClock.uptimeMillis() // Last crash more than 3 s ago
    ) {/*from w  ww  . ja  v  a 2  s . c  o  m*/
        // Save crash time
        sLastForceFinish = SystemClock.uptimeMillis();

        // Restart activity
        updateIntent();
        Intent intent = new Intent(this, IntentEditorActivity.class);
        intent.putExtra(EXTRA_INTENT, mEditedIntent);
        intent.putExtra(EXTRA_COMPONENT_TYPE, mComponentType);
        intent.putExtra(EXTRA_METHOD_ID, mMethodId);
        intent.putExtra(EXTRA_INTENT_FILTERS, mAttachedIntentFilters);
        if (mLocalState != null) {
            Bundle extra = new Bundle(1);
            RunAsInitReceiver.putBinderInBundle(extra, EXTRA_LOCAL_STATE, mLocalState);
            intent.putExtras(extra);
        }

        startActivity(intent);
    }

    super.onDestroy();
}

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

/**
 * Sends a DATA broadcast for the probe, and records the time.
 *//*from   w  w w. j a  v  a 2  s  .c o  m*/
protected void sendProbeData(long epochTimestamp, Bundle data) {
    // Should always be loaded when enabled
    Intent dataIntent = new Intent(ACTION_DATA);
    dataIntent.putExtras(data);
    callback(epochTimestamp, dataIntent, null);
}

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

public void sendProbeDetails(PendingIntent callback) {
    Details details = new Details(getClass().getName(), getDisplayName(), getRequiredPermissions(),
            getRequiredFeatures(), getAvailableParameters());
    Intent detailsIntent = new Intent(ACTION_DETAILS);
    detailsIntent.putExtras(details.getBundle());
    callback(Utils.millisToSeconds(System.currentTimeMillis()), detailsIntent, callback);
}

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

public void sendProbeStatus(PendingIntent callback) {
    Status status = new Status(getClass().getName(), enabled, isRunning(), getNextRunTime(),
            getPreviousRunTime());//  w w  w  .  java2s.c  om
    Intent statusValuesIntent = new Intent(ACTION_STATUS);
    statusValuesIntent.putExtras(status.getBundle());
    callback(Utils.millisToSeconds(System.currentTimeMillis()), statusValuesIntent, callback);
}