List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:org.chromium.ChromeNotifications.java
private static void triggerJavascriptEventNow(Context context, ComponentName componentName, EventInfo eventInfo) {//from w w w. ja v a 2 s .c o m Intent intent = new Intent(); intent.setComponent(componentName); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); if (NOTIFICATION_CLICKED_ACTION.equals(eventInfo.action)) { webView.sendJavascript("chrome.notifications.triggerOnClicked('" + eventInfo.notificationId + "')"); context.startActivity(intent); } else if (NOTIFICATION_CLOSED_ACTION.equals(eventInfo.action)) { PendingIntent pendingIntent = makePendingIntent(context, componentName, NOTIFICATION_CLICKED_ACTION, eventInfo.notificationId, -1, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { pendingIntent.cancel(); } webView.sendJavascript("chrome.notifications.triggerOnClosed('" + eventInfo.notificationId + "')"); } else if (NOTIFICATION_BUTTON_CLICKED_ACTION.equals(eventInfo.action)) { webView.sendJavascript("chrome.notifications.triggerOnButtonClicked('" + eventInfo.notificationId + "', " + eventInfo.buttonIndex + ")"); context.startActivity(intent); } }
From source file:androidx.media.session.MediaButtonReceiver.java
/** * Creates a broadcast pending intent that will send a media button event. The {@code action} * will be translated to the appropriate {@link KeyEvent}, and sent to the provided media * button receiver via the pending intent. The {@code action} should be one of the following: * <ul>//from ww w . ja va 2 s .c om * <li>{@link PlaybackStateCompat#ACTION_PLAY}</li> * <li>{@link PlaybackStateCompat#ACTION_PAUSE}</li> * <li>{@link PlaybackStateCompat#ACTION_SKIP_TO_NEXT}</li> * <li>{@link PlaybackStateCompat#ACTION_SKIP_TO_PREVIOUS}</li> * <li>{@link PlaybackStateCompat#ACTION_STOP}</li> * <li>{@link PlaybackStateCompat#ACTION_FAST_FORWARD}</li> * <li>{@link PlaybackStateCompat#ACTION_REWIND}</li> * <li>{@link PlaybackStateCompat#ACTION_PLAY_PAUSE}</li> * </ul> * * @param context The context of the application. * @param mbrComponent The full component name of a media button receiver where you want to send * this intent. * @param action The action to be sent via the pending intent. * @return Created pending intent, or null if the given component name is null or the * {@code action} is unsupported/invalid. */ public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, @MediaKeyAction long action) { if (mbrComponent == null) { Log.w(TAG, "The component name of media button receiver should be provided."); return null; } int keyCode = PlaybackStateCompat.toKeyCode(action); if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { Log.w(TAG, "Cannot build a media button pending intent with the given action: " + action); return null; } Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mbrComponent); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode)); return PendingIntent.getBroadcast(context, keyCode, intent, 0); }
From source file:com.adguard.android.commons.BrowserUtils.java
public static void startBrowser(Context context, ComponentName component) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(component); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);/*from ww w .ja v a 2 s. c o m*/ }
From source file:edu.umich.oasis.client.OASISConnection.java
public static ServiceConnection bind(final Context context, final Callback callback) { final ServiceConnection connection = new ServiceConnection() { private OASISConnection conn; @Override// ww w .ja v a 2s. c o m public void onServiceConnected(ComponentName componentName, IBinder iBinder) { IOASISService service = IOASISService.Stub.asInterface(iBinder); conn = new OASISConnection(context, this, service); try { callback.onConnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onConnect", e); } } @Override public void onServiceDisconnected(ComponentName componentName) { Log.e(TAG, "Lost Binder connection to OASIS"); if (callback instanceof DisconnectCallback) { try { ((DisconnectCallback) callback).onDisconnect(conn); } catch (Exception e) { Log.e(TAG, "Unhandled exception in onDisconnect", e); } } conn.closeInternal(); } }; Intent serviceIntent = new Intent(); serviceIntent.setComponent(OASISFramework.getServiceComponent(context)); if (context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE | Context.BIND_ADJUST_WITH_ACTIVITY | Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) { return connection; } else { return null; } }
From source file:Main.java
public static void callGoogleTranslateApps(Context context, String word, String toLang) { try {//w w w .j a va2 s . c o m Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.putExtra("key_text_input", word); i.putExtra("key_text_output", ""); i.putExtra("key_language_from", "en"); i.putExtra("key_language_to", "vi"); i.putExtra("key_suggest_translation", ""); i.putExtra("key_from_floating_window", false); i.setComponent(new ComponentName("com.google.android.apps.translate", "com.google.android.apps.translate.TranslateActivity")); context.startActivity(i); } catch (ActivityNotFoundException ex) { Toast.makeText(context, "Google translate app is not installed", Toast.LENGTH_SHORT).show(); ex.printStackTrace(); } }
From source file:Main.java
public static void startApkActivity(final Context ctx, String packageName) { PackageManager pm = ctx.getPackageManager(); PackageInfo pi;/*from www. ja v a 2s.com*/ try { pi = pm.getPackageInfo(packageName, 0); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(pi.packageName); List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String className = ri.activityInfo.name; intent.setComponent(new ComponentName(packageName, className)); ctx.startActivity(intent); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static void startApkActivity(final Context ctx, String packageName) { PackageManager pm = ctx.getPackageManager(); PackageInfo pi;//w w w .java 2 s . co m try { pi = pm.getPackageInfo(packageName, 0); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(pi.packageName); List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String className = ri.activityInfo.name; intent.setComponent(new ComponentName(packageName, className)); ctx.startActivity(intent); } } catch (NameNotFoundException e) { e.printStackTrace(); } }
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);/*from ww w .j av a 2 s.c o m*/ intent.setComponent(new ComponentName(pkg, cls)); startActivityForResult(intent, activity, requestCode, options); }
From source file:com.phonemetra.account.util.AccountUtils.java
private static Intent getWifiSetupIntent(Context context) { Intent intent = new Intent(); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(Account.WIFI_COMPONENT_PKG, Account.WIFI_COMPONENT_CLASS)); intent.putExtra(Account.EXTRA_FIRST_RUN, true); intent.putExtra(Account.EXTRA_ALLOW_SKIP, false); intent.putExtra(Account.EXTRA_SHOW_BUTTON_BAR, true); intent.putExtra(Account.EXTRA_ONLY_ACCESS_POINTS, true); intent.putExtra(Account.EXTRA_AUTO_FINISH, true); return intent; }
From source file:io.hypertrack.sendeta.util.images.EasyImage.java
private static Intent createChooserIntent(Context context, String chooserTitle, boolean showGallery) throws IOException { Uri outputFileUri = createCameraPictureFile(context); List<Intent> cameraIntents = new ArrayList<>(); Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> camList = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : camList) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName);//from w w w .ja v a 2s . c o m intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); cameraIntents.add(intent); } Intent galleryIntent; if (showGallery) { galleryIntent = createGalleryIntent(); } else { galleryIntent = createDocumentsIntent(); } Intent chooserIntent = Intent.createChooser(galleryIntent, chooserTitle); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()])); return chooserIntent; }