Example usage for android.content Intent putExtra

List of usage examples for android.content Intent putExtra

Introduction

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

Prototype

@Deprecated
@UnsupportedAppUsage
public @NonNull Intent putExtra(String name, IBinder value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:Main.java

/**
 * Notifies UI to display a message.//from  w ww.ja  va2 s . c  om
 * <p>
 * This method is defined in the common helper because it's used both by
 * the UI and the background service.
 *
 * @param context application's context.
 * @param message message to be displayed.
 * @param loc location that road side sensor has.
 */
static void displayMessage(Context context, String message, Location loc) {
    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.putExtra(EXTRA_MESSAGE, message);
    intent.putExtra(LATITUDE, loc.getLatitude());
    intent.putExtra(LONGITUDE, loc.getLongitude());
    context.sendBroadcast(intent);

}

From source file:Main.java

public static void createShortcut(Context ctx, String shortCutName, int iconId, Intent presentIntent) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(ctx, iconId));
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent);
    ctx.sendBroadcast(shortcutIntent);/*w  ww  .  j a v a  2 s  .c om*/
}

From source file:Main.java

/**
 * Enable the bluetooth adapter.//from   w  ww. jav a2  s.c o m
 */
public static void bluetoothEnable(Activity activity, boolean discoverable, int reqCode) {
    if (discoverable) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        activity.startActivityForResult(discoverableIntent, reqCode);
    } else {
        Intent bluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(bluetoothIntent, reqCode);
    }
}

From source file:Main.java

public static void enableDiscovery(Context context) {
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVERABLE_SECONDS);
    context.startActivity(discoverableIntent);
}

From source file:Main.java

/**
 * Set badge count/*from  w w  w  .java2  s  . co m*/
 * 
 * @param context The context of the application package.
 * @param count Badge count to be set
 */
public static void setBadgeCount(Context context, int count) {
    Intent badgeIntent = new Intent(ACTION_BADGE_COUNT_UPDATE);
    badgeIntent.putExtra(EXTRA_BADGE_COUNT, count);
    badgeIntent.putExtra(EXTRA_BADGE_COUNT_PACKAGE_NAME, context.getPackageName());
    badgeIntent.putExtra(EXTRA_BADGE_COUNT_CLASS_NAME, getLauncherClassName(context));
    context.sendBroadcast(badgeIntent);
}

From source file:Main.java

/**
 * Set badge count//from www .ja  v  a2s .  c  o  m
 *
 * @param context The context of the application package.
 * @param count   Badge count to be set
 */
private static void setBadgeCount4Default(Context context, int count) {
    Intent badgeIntent = new Intent(ACTION_BADGE_COUNT_UPDATE);
    badgeIntent.putExtra(EXTRA_BADGE_COUNT, count);
    badgeIntent.putExtra(EXTRA_BADGE_COUNT_PACKAGE_NAME, context.getPackageName());
    badgeIntent.putExtra(EXTRA_BADGE_COUNT_CLASS_NAME, getLauncherClassName(context));
    context.sendBroadcast(badgeIntent);
}

From source file:Main.java

public static void putDataIntoIntent(Intent intent, String str) {
    Bundle bundle = new Bundle();
    bundle.putString("data", str);
    intent.putExtra("data", bundle);
}

From source file:Main.java

/** Launch a SMS intent if the device is capable.
 *
 * @param activity The parent activity (for context)
 * @param number The number to sms (not the full URI)
 * @param text The sms body//from  www  .j av a2  s . c  o  m
 */
public static void launchSmsIntent(final Activity activity, String number, String text) {
    Log.i(LOG_TAG, "Launch SMS intent to " + number);
    // create sms intent
    Uri smsUri = Uri.parse("smsto:" + number);
    Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
    smsIntent.putExtra("sms_body", text);
    // make sure there is an activity which can handle the intent.
    PackageManager smspackageManager = activity.getPackageManager();
    List<ResolveInfo> smsresolveInfos = smspackageManager.queryIntentActivities(smsIntent, 0);
    if (smsresolveInfos.size() > 0) {
        activity.startActivity(smsIntent);
    }
}

From source file:Main.java

public static void shareContent(Context context, String subject, String summary, String url) {

    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, url);
    context.startActivity(Intent.createChooser(intent, "Share"));

}

From source file:Main.java

static void saveToContact(Context context, String number) {
    Intent intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
    intent.putExtra(Contacts.Intents.Insert.PHONE, number);
    context.startActivity(intent);//from  ww  w  .j  a va  2 s  .com
}