List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:Main.java
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) { //Retrieve all services that can match the given intent PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0); //Make sure only one match was found if (resolveInfo == null || resolveInfo.size() != 1) { return null; }// www.j a v a2s. c om //Get component info and create ComponentName ResolveInfo serviceInfo = resolveInfo.get(0); String packageName = serviceInfo.serviceInfo.packageName; String className = serviceInfo.serviceInfo.name; ComponentName component = new ComponentName(packageName, className); //Create a new intent. Use the old one for extras and such reuse Intent explicitIntent = new Intent(implicitIntent); //Set the component to be explicit explicitIntent.setComponent(component); return explicitIntent; }
From source file:Main.java
public static void openNetSetting(Activity act) { Intent intent = new Intent(); ComponentName cm = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings"); intent.setComponent(cm); intent.setAction("android.intent.action.VIEW"); act.startActivityForResult(intent, 0); }
From source file:Main.java
private static Intent getComponentIntent(String packageName, String className, Bundle bundle) { Intent intent = new Intent(Intent.ACTION_VIEW); if (bundle != null) intent.putExtras(bundle);/*from w w w . j av a 2 s. c om*/ ComponentName cn = new ComponentName(packageName, className); intent.setComponent(cn); return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
From source file:Main.java
public static Intent getComponentIntent(String packageName, String className, Bundle bundle) { Intent intent = new Intent(Intent.ACTION_VIEW); if (bundle != null) intent.putExtras(bundle);//from ww w . java 2s . c om ComponentName cn = new ComponentName(packageName, className); intent.setComponent(cn); return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
From source file:com.webnetmobile.tools.Redirector.java
public static void showActivity(Context context, Class activityClass, Intent intent) { String className = activityClass.getName(); ComponentName comp = new ComponentName(context.getPackageName(), className); intent.setComponent(comp); showActivity(context, intent);//from w ww.j a v a2s . co m }
From source file:Main.java
/** * open another app//from ww w . j ava 2s .c om * @param context * @param packageName * @throws NameNotFoundException */ public static void openApp(Context context, String packageName) throws NameNotFoundException { PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, 0); Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(pi.packageName); List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0); Iterator<ResolveInfo> iterator = apps.iterator(); while (iterator.hasNext()) { ResolveInfo ri = iterator.next(); if (ri != null) { packageName = ri.activityInfo.packageName; String className = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName, className); intent.setComponent(cn); context.startActivity(intent); } } }
From source file:Main.java
public static boolean openAppActivity(Context context, String packageName, String activityName) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ComponentName cn = new ComponentName(packageName, activityName); intent.setComponent(cn); try {//w w w . j a v a2s .c o m context.startActivity(intent); return true; } catch (ActivityNotFoundException e) { return false; } }
From source file:com.android.usbtuner.setup.TunerSetupActivity.java
/** * Returns a {@link Intent} to launch the USB tuner TV input service. * * @param context a {@link Context} instance *//*from w w w . ja v a 2 s.c o m*/ public static Intent createSetupActivity(Context context) { String inputId = TvContract .buildInputId(new ComponentName(context.getPackageName(), UsbTunerTvInputService.class.getName())); // Make an intent to launch the setup activity of USB tuner TV input. Intent intent = TvCommonUtils.createSetupIntent(new Intent(context, TunerSetupActivity.class), inputId); intent.putExtra(TvCommonConstants.EXTRA_INPUT_ID, inputId); Intent tvActivityIntent = new Intent(); tvActivityIntent.setComponent(new ComponentName(context, TV_ACTIVITY_CLASS_NAME)); intent.putExtra(TvCommonConstants.EXTRA_ACTIVITY_AFTER_COMPLETION, tvActivityIntent); return intent; }
From source file:com.commonsware.android.broadcast.fanout.MainActivity.java
private static void sendImplicitBroadcast(Context ctxt, Intent i) { PackageManager pm = ctxt.getPackageManager(); List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0); for (ResolveInfo resolveInfo : matches) { Intent explicit = new Intent(i); ComponentName cn = new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name); explicit.setComponent(cn); ctxt.sendBroadcast(explicit);/*from w ww . j av a2s .co m*/ } }
From source file:Main.java
public static void jumpToSystemDownloadApk(Context context, String url) { Intent intent = new Intent("android.intent.action.VIEW"); Uri data = Uri.parse(Html.fromHtml(url).toString()); intent.setData(data);/*from ww w .j av a2 s.c o m*/ intent.setPackage("com.google.android.browser"); intent.addCategory("android.intent.category.BROWSABLE"); intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity")); context.startActivity(intent); }