List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:Main.java
/** * Enable broadcast received component./*from w w w . j a v a 2 s. c o m*/ * @param c * @param component */ public static void enableReceiver(Context c, Class component) { ComponentName receiver = new ComponentName(c, component); PackageManager pm = c.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:Main.java
/** * Disable broadcast received component. * @param c//from ww w . java 2 s . com * @param component */ public static void disableReceiver(Context c, Class component) { ComponentName receiver = new ComponentName(c, component); PackageManager pm = c.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
From source file:Main.java
/** * Restituisce il numero di versione dell'applicazione * Se il numero di versione (versionName) termina con il carattere punto * allora viene aggiunto anche il numero della build *//*from www .j av a 2 s . c o m*/ public static String getApplicationVersion(Context context, Class<?> thisClass) { PackageInfo pinfo = null; String version = null; try { ComponentName comp = new ComponentName(context, thisClass); pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); version = pinfo.versionName; if (version.endsWith(".")) version += pinfo.versionCode; } catch (Exception e) { } return version; }
From source file:Main.java
/** * Try to pick the app to handle this intent. * @param context/*from w w w . j a v a2s. 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:Main.java
/** * Load the settings activity of a particular joyn client to enable or * disable the client// ww w. j a v a 2s . c o m * * @param context Application context * @param appInfo Application info */ public static void loadJoynClientSettings(Context context, ResolveInfo appInfo) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName(appInfo.activityInfo.packageName, appInfo.activityInfo.name)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); context.startActivity(intent); }
From source file:Main.java
public static void startAppByPackageName(Context context, String packageName) { PackageInfo pi = null;/*w w w . jav a 2 s. c o m*/ try { pi = context.getPackageManager().getPackageInfo(packageName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } 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); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String packageName1 = ri.activityInfo.packageName; String className = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName1, className); intent.setComponent(cn); context.startActivity(intent); } }
From source file:Main.java
private static void shareImageOnFacebook(String imagePath, Context context) { Log.d("CitationsManager-ShareOnFb", "sharing the image " + imagePath); Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); // shareIntent.putExtra(Intent.EXTRA_TEXT, "www.google.com"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); PackageManager pm = context.getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { Log.d("CitationsManager-ShareOnFb", app.activityInfo.name); if ((app.activityInfo.name).contains("com.facebook") && !(app.activityInfo.name).contains("messenger") && !(app.activityInfo.name).contains("pages")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); shareIntent.setComponent(name); context.startActivity(shareIntent); break; }// ww w. j a v a 2s.com } }
From source file:com.commonsware.android.jobsched.content.DemoJobService.java
static void schedule(Context ctxt) { ComponentName cn = new ComponentName(ctxt, DemoJobService.class); JobInfo.TriggerContentUri trigger = new JobInfo.TriggerContentUri(CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS); JobInfo.Builder b = new JobInfo.Builder(ME_MYSELF_AND_I, cn).addTriggerContentUri(trigger); JobScheduler jobScheduler = (JobScheduler) ctxt.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(b.build());//w ww . j ava 2s .c om }
From source file:Main.java
/** * open another app//from ww w . ja v a 2 s .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:com.dolphin.push.GoogleCloudMessagingBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { ComponentName comp = new ComponentName(context.getPackageName(), serviceName()); startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);//from w w w.ja va 2 s .c o m }