List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.mods.grx.settings.utils.Utils.java
public static String get_label_from_packagename_activityname(Context context, String nombre_paquete, String nombre_actividad) { String etiqueta = "-"; Intent intent = new Intent(); intent.setComponent(new ComponentName(nombre_paquete, nombre_actividad)); ResolveInfo ri = context.getPackageManager().resolveActivity(intent, 0); if (ri != null) { etiqueta = ri.loadLabel(context.getPackageManager()).toString(); } else/*from w ww .j ava2 s. c om*/ etiqueta = ""; ApplicationInfo aitemp; String eti_app = ""; try { aitemp = context.getPackageManager().getApplicationInfo(ri.activityInfo.packageName, 0); eti_app = context.getPackageManager().getApplicationLabel(aitemp).toString(); } catch (Exception e) { e.printStackTrace(); } if (eti_app.equals(etiqueta)) etiqueta = nombre_actividad; else { etiqueta = etiqueta; } if (etiqueta.contains(".")) etiqueta = Utils.format_label(etiqueta); return etiqueta; }
From source file:com.blanyal.remindme.MainActivity.java
public static Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent, Context context) { PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0); if (resolveInfoList == null || resolveInfoList.size() != 1) { return null; }/*from w w w . j ava 2 s . co m*/ ResolveInfo serviceInfo = resolveInfoList.get(0); Log.v("vbharill", "package name" + serviceInfo.serviceInfo.packageName); Log.v("vbharill", "service name" + serviceInfo.serviceInfo.name); ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name); Intent explicitIntent = new Intent(implicitIntent); explicitIntent.setComponent(component); return explicitIntent; }
From source file:com.felkertech.n.ActivityUtils.java
/** * Opens the correct intent to start editing the channel. * * @param activity The activity you're calling this from. * @param channelUrl The channel's media url.m */// w w w .ja v a 2 s .c om public static void editChannel(final Activity activity, final String channelUrl) { ChannelDatabase cdn = ChannelDatabase.getInstance(activity); final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl); if (channelUrl == null || jsonChannel == null) { try { Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show(); } catch (RuntimeException e) { Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid)); } return; } if (jsonChannel.getPluginSource() != null) { // Search through all plugins for one of a given source PackageManager pm = activity.getPackageManager(); try { pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES); // Open up this particular activity Intent intent = new Intent(); intent.setComponent(jsonChannel.getPluginSource()); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT); Log.d(TAG, "Editing channel " + jsonChannel.toString()); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString()); activity.startActivity(intent); } catch (PackageManager.NameNotFoundException e) { new MaterialDialog.Builder(activity) .title(activity.getString(R.string.plugin_not_installed_title, jsonChannel.getPluginSource().getPackageName())) .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app) .negativeText(R.string.open_in_another_plugin) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + jsonChannel.getPluginSource().getPackageName())); activity.startActivity(i); } @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); openPluginPicker(false, channelUrl, activity); } }).show(); Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed, jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show(); openPluginPicker(false, channelUrl, activity); } } else { if (DEBUG) { Log.d(TAG, "No specified source"); } openPluginPicker(false, channelUrl, activity); } }
From source file:Main.java
/** * Open Play Store application or its web version if no play store * available./* ww w. j av a2s . c o m*/ * * @param c : Android Context */ public static void actionDisplayPlayStore(Context c) { // Retrieve list of application that understand market Intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=org.alfresco.mobile.android.application")); final PackageManager mgr = c.getPackageManager(); List<ResolveInfo> list = mgr.queryIntentActivities(intent, 0); // By default we redirect to the webbrowser version of play store. intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://play.google.com/")); for (ResolveInfo resolveInfo : list) { // If we find something related to android we open the application // version of play store. if (resolveInfo.activityInfo.applicationInfo.packageName.contains("android")) { intent.setComponent(new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name)); intent.setData(Uri.parse("market://")); break; } } c.startActivity(intent); }
From source file:github.popeen.dsub.util.Notifications.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote, boolean isSingleFile, boolean shouldFastForward) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {/*from w ww . j av a 2 s . c o m*/ ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context); Bitmap bitmap = null; if (imageLoader != null) { bitmap = imageLoader.getCachedImage(context, song, false); } if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { imageLoader.setNowPlayingSmall(bitmap); rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); boolean persistent = Util.getPreferences(context) .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false); if (persistent) { if (expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); if (shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward); } } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); if (shouldFastForward) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward); } else { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); } rv.setImageViewResource(R.id.control_next, R.drawable.notification_close); } } else if (shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { // Necessary for switching back since it appears to re-use the same layout rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward); } // Create actions for media buttons int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0; if (expanded) { pause = R.id.control_pause; if (shouldFastForward) { rewind = R.id.control_previous; fastForward = R.id.control_next; } else { previous = R.id.control_previous; next = R.id.control_next; } if (remote || persistent) { close = R.id.notification_close; rv.setViewVisibility(close, View.VISIBLE); } } else { if (persistent) { pause = R.id.control_previous; if (shouldFastForward) { fastForward = R.id.control_pause; } else { next = R.id.control_pause; } close = R.id.control_next; } else { if (shouldFastForward) { rewind = R.id.control_previous; fastForward = R.id.control_next; } else { previous = R.id.control_previous; next = R.id.control_next; } pause = R.id.control_pause; } } if (isSingleFile) { if (previous > 0) { rv.setViewVisibility(previous, View.GONE); previous = 0; } if (rewind > 0) { rv.setViewVisibility(rewind, View.GONE); rewind = 0; } if (next > 0) { rv.setViewVisibility(next, View.GONE); next = 0; } if (fastForward > 0) { rv.setViewVisibility(fastForward, View.GONE); fastForward = 0; } } PendingIntent pendingIntent; if (previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(previous, pendingIntent); } if (rewind > 0) { Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND"); rewindIntent.setComponent(new ComponentName(context, DownloadService.class)); rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND)); pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0); rv.setOnClickPendingIntent(rewind, pendingIntent); } if (pause > 0) { if (playing) { Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadService.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_START"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } } if (next > 0) { Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadService.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(next, pendingIntent); } if (fastForward > 0) { Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD"); fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class)); fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD)); pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0); rv.setOnClickPendingIntent(fastForward, pendingIntent); } if (close > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(close, pendingIntent); } }
From source file:Main.java
/** * Try to pick the app to handle this intent. * @param context//from w ww . j ava 2 s .c o m * @param intent * @param matchMe E.g. "twitter" Pick the first app whose name contains this. * Can be null for pick-anything. * @return true if a match was found */ public static boolean pickIntentHandler(Context context, Intent intent, String matchMe) { final PackageManager pm = context.getPackageManager(); final List<ResolveInfo> activityList = pm.queryIntentActivities(intent, 0); List<String> handlers = new ArrayList(activityList.size()); for (ResolveInfo app : activityList) { String name = app.activityInfo.name; handlers.add(name); if (matchMe == null || name.contains(matchMe)) { ActivityInfo activity = app.activityInfo; ComponentName compname = new ComponentName(activity.applicationInfo.packageName, activity.name); // intent.addCategory(Intent.CATEGORY_LAUNCHER); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.setComponent(compname); return true; } } Log.d("pick-intent", "No match for " + matchMe + " in " + handlers); return false; }
From source file:jahirfiquitiva.iconshowcase.tasks.LoadAppsToRequest.java
private static ResolveInfo getResolveInfo(String componentString) { Intent intent = new Intent(); // Example format: //intent.setComponent(new ComponentName("com.myapp", "com.myapp.launcher.settings")); if (componentString != null) { String[] split = null;/*from w ww .j av a 2 s. c om*/ try { split = componentString.split("/"); } catch (ArrayIndexOutOfBoundsException e) { //Do nothing } if (split != null) { try { components.add(componentString); intent.setComponent(new ComponentName(split[0], split[1])); } catch (ArrayIndexOutOfBoundsException e1) { //Do nothing } } return mPackageManager.resolveActivity(intent, 0); } else { return null; } }
From source file:com.linkbubble.MainApplication.java
public static boolean openInBrowser(Context context, Intent intent, boolean showToastIfNoBrowser, boolean braveBrowser) { boolean activityStarted = false; ComponentName defaultBrowserComponentName = Settings.get().getDefaultBrowserComponentName(context); if (defaultBrowserComponentName != null) { intent.setComponent(defaultBrowserComponentName); context.startActivity(intent);/*from w w w . j a v a 2 s . c om*/ activityStarted = true; CrashTracking.log("MainApplication.openInBrowser()"); } else if (braveBrowser) { try { Intent gpsIntent = new Intent(Intent.ACTION_VIEW); gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); gpsIntent.setData(Uri.parse("market://details?id=" + context.getResources().getString(R.string.tab_based_browser_id_name))); context.startActivity(gpsIntent); activityStarted = true; Settings settings = Settings.get(); if (null != settings) { settings.initiateBrowsersUpdate(); } } catch (android.content.ActivityNotFoundException anfe) { CrashTracking.log("MainApplication.openInBrowser() could not open google play"); } } if (activityStarted == false && showToastIfNoBrowser) { Toast.makeText(context, R.string.no_default_browser, Toast.LENGTH_LONG).show(); } return activityStarted; }
From source file:org.onepf.opfpush.gcm_migrate_sample.GCMBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { intent.setComponent(new ComponentName(context, GCMIntentService.class)); startWakefulService(context, intent); setResultCode(Activity.RESULT_OK);// www . ja va2s .co m }
From source file:com.onesignal.BootUpReceiver.java
@Override public void onReceive(Context context, Intent intent) { Intent intentForService = new Intent(); intentForService.setComponent( new ComponentName(context.getPackageName(), NotificationRestoreService.class.getName())); startWakefulService(context, intentForService); }