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:Main.java

public static boolean startActivity(Activity a, String packageName, Bundle args) {
    PackageManager pm = a.getPackageManager();
    boolean result = true;
    try {/*from w ww .j a v  a  2s. c o m*/
        Intent intent = pm.getLaunchIntentForPackage(packageName);
        if (null != intent) {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (args != null)
                intent.putExtras(args);
            a.startActivity(intent);
        } else {
            result = startActivityUsingScheme(a, packageName, args);
        }
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = startActivityUsingScheme(a, packageName, args);
    }
    return result;
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateBroadcast(Context context, Bundle extras) {
    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    broadcastIntent.putExtras(extras);

    JSONObject dataObject = new JSONObject();
    try {//from   w ww  . j a va  2 s. c  om
        if (extras.containsKey("title")) {
            dataObject.put("title", extras.get("title"));
        }
        if (extras.containsKey("u")) {
            dataObject.put("userdata", new JSONObject(extras.getString("u")));
        }
    } catch (JSONException e) {
        // pass
    }

    broadcastIntent.putExtra(BasePushMessageReceiver.DATA_KEY, dataObject.toString());

    context.sendBroadcast(broadcastIntent, context.getPackageName() + ".permission.C2D_MESSAGE");
}

From source file:com.android.contacts.util.AccountFilterUtil.java

/**
 * Start editor intent; and if filter is an account filter, we pass account info to editor so
 * as to create a contact in that account.
 *//*w  w w .j av a 2s  .  c om*/
public static void startEditorIntent(Context context, Intent src, ContactListFilter filter) {
    final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
    intent.putExtras(src);

    // If we are in account view, we pass the account explicitly in order to
    // create contact in the account. This will prevent the default account dialog
    // from being displayed.
    if (!isAllContactsFilter(filter) && filter.accountName != null && filter.accountType != null) {
        final Account account = new Account(filter.accountName, filter.accountType);
        intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, account);
        intent.putExtra(Intents.Insert.EXTRA_DATA_SET, filter.dataSet);
    } else if (isDeviceContactsFilter(filter)) {
        intent.putExtra(ContactEditorActivity.EXTRA_ACCOUNT_WITH_DATA_SET, filter.toAccountWithDataSet());
    }

    try {
        ImplicitIntentsUtil.startActivityInApp(context, intent);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(context, R.string.missing_app, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.ctg.ctvideo.activities.VideoActivity.java

public static Intent newIntent(Context context, Bundle bundle) {
    Intent intent = new Intent(context, VideoActivity.class);
    intent.putExtras(bundle);
    return intent;
}

From source file:Main.java

public static <T> void putBundle(String key, T data, Intent intent) {
    Bundle bundle = new Bundle();

    try {//from   ww w  .  j  a va2  s . co m

        if (data instanceof Parcelable) {
            bundle.putParcelable(key, (Parcelable) data);
        } else if (data instanceof Serializable) {
            bundle.putSerializable(key, (Serializable) data);
        }
        intent.putExtras(bundle);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void goToActivity(Context packageContext, Class<?> targetActivityClass, String paraName,
        Object paramValue) {/*  w  w w.  j av  a2 s.  c om*/
    Intent intent = new Intent();
    intent.setClass(packageContext, targetActivityClass);
    Bundle bundle = new Bundle();
    if (paramValue instanceof String) {
        bundle.putString(paraName, (String) paramValue);
    } else {
        bundle.putInt(paraName, (int) paramValue);
    }
    intent.putExtras(bundle);
    packageContext.startActivity(intent);
}

From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java

/**
 * activity// w  ww .j  a va  2  s  .  c  o m
 * @param from ?activity
 * @param to activity
 * @param extras ??
 */
public static void changeActivity(Activity from, Class<?> to, Bundle extras) {
    // Intent intent = setIntent(from, to, extras);
    Intent intent = new Intent();
    if (extras != null)
        intent.putExtras(extras);
    intent.setClass(from.getBaseContext(), to);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    from.startActivity(intent);
    //from.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    from.overridePendingTransition(R.anim.enter_righttoleft, R.anim.exit_righttoleft);
}

From source file:com.airbop.library.simple.CommonUtilities.java

static void onGCMMessage(Context context, Bundle bundle) {
    Intent intent = new Intent(GCM_MESSAGE_ACTION);
    intent.putExtras(bundle);
    String packageName = context.getPackageName();
    intent.setPackage(packageName);/*from   ww  w  . j a v a2  s .  c  om*/

    //sendLocalBroadcast(context, intent);
    context.sendBroadcast(intent);
}

From source file:Main.java

private static void startActivityForResult(final Activity activity, final Bundle extras, final String pkg,
        final String cls, final int requestCode, final Bundle options) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (extras != null)
        intent.putExtras(extras);
    intent.setComponent(new ComponentName(pkg, cls));
    startActivityForResult(intent, activity, requestCode, options);
}

From source file:Main.java

public static void sendSchemeForResultAddMediaStack(Activity context, String mediaActivityUrl, String url,
        int requestCode, Bundle bundle) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(mediaActivityUrl));
    intent.addFlags(67108864);/* www  . j  a v a2s  .  c om*/
    context.startActivity(intent);
    intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
    if (bundle != null) {
        intent.putExtras(bundle);
    }

    context.startActivityForResult(intent, requestCode);
}