List of usage examples for android.content Intent getComponent
public @Nullable ComponentName getComponent()
From source file:com.android.launcher4.InstallShortcutReceiver.java
public static void removeFromInstallQueue(SharedPreferences sharedPrefs, ArrayList<String> packageNames) { if (packageNames.isEmpty()) { return;// w ww .jav a 2 s. c o m } synchronized (sLock) { Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null); if (DBG) { Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames); } if (strings != null) { Set<String> newStrings = new HashSet<String>(strings); Iterator<String> newStringsIter = newStrings.iterator(); while (newStringsIter.hasNext()) { String json = newStringsIter.next(); try { JSONObject object = (JSONObject) new JSONTokener(json).nextValue(); Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0); String pn = launchIntent.getPackage(); if (pn == null) { pn = launchIntent.getComponent().getPackageName(); } if (packageNames.contains(pn)) { newStringsIter.remove(); } } catch (org.json.JSONException e) { Log.d(TAG, "Exception reading shortcut to remove: " + e); } catch (java.net.URISyntaxException e) { Log.d(TAG, "Exception reading shortcut to remove: " + e); } } sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>(newStrings)).commit(); } } }
From source file:com.android.launcher3.InstallShortcutReceiver.java
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead.//from w ww . j a v a 2s .c om */ private static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead./*w w w.j a va 2 s .com*/ */ @Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonIntent(Intent data) throws JSONException { JSONObject result = new JSONObject(); result.put("data", data.getDataString()); result.put("type", data.getType()); result.put("extras", build(data.getExtras())); result.put("categories", build(data.getCategories())); result.put("action", data.getAction()); ComponentName component = data.getComponent(); if (component != null) { result.put("packagename", component.getPackageName()); result.put("classname", component.getClassName()); }/*w w w . j a v a 2s. c o m*/ result.put("flags", data.getFlags()); return result; }
From source file:com.mods.grx.settings.utils.Utils.java
public static Drawable get_icon_from_intent(Context context, Intent intent) { Drawable drawable = null;//from ww w . j av a 2 s . co m try { ComponentName c_n = intent.getComponent(); if (c_n != null) { ActivityInfo a_i = context.getPackageManager().getActivityInfo(c_n, 0); if (a_i != null) drawable = a_i.loadIcon(context.getPackageManager()); } } catch (Exception e) { } if (drawable == null) { ResolveInfo ri = context.getPackageManager().resolveActivity(intent, 0); if (ri != null) { try { drawable = ri.loadIcon(context.getPackageManager()); } catch (Exception e) { } } } //if(drawable==null) drawable=context.getDrawable(R.drawable.ic_no_encontrada); return drawable; }
From source file:com.mods.grx.settings.utils.Utils.java
public static String get_activity_name_from_package_name(Context context, String packageName) { String className = null;// w w w .j a v a2 s .com try { Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); className = launchIntent.getComponent().getClassName(); } catch (Exception e) { } return className; }
From source file:com.mods.grx.settings.utils.Utils.java
public static String get_activity_label_from_intent(Context context, Intent intent) { String string;// w w w .j a va2 s. c om string = intent.getStringExtra(Common.EXTRA_URI_LABEL); if (string == null) { try { ComponentName c_n = intent.getComponent(); if (c_n != null) { ActivityInfo a_i = context.getPackageManager().getActivityInfo(c_n, 0); if (a_i != null) string = a_i.loadLabel(context.getPackageManager()).toString(); } } catch (Exception e) { } } if (string == null) string = "?"; return string; }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * INTERNAL method used to get the default launcher activity for the app. * If there is no launchable activity, this returns null. * * @param context A valid context. Must not be null. * @return A valid activity class, or null if no suitable one is found *//*from ww w .java 2 s .c o m*/ @SuppressWarnings("unchecked") private static Class<? extends Activity> getLauncherActivity(Context context) { Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); if (intent != null) { try { return (Class<? extends Activity>) Class.forName(intent.getComponent().getClassName()); } catch (ClassNotFoundException e) { //Should not happen, print it to the log! Log.e(TAG, "Failed when resolving the restart activity class via getLaunchIntentForPackage, stack trace follows!", e); } } return null; }
From source file:tm.alashow.datmusic.android.IntentManager.java
public void openIntentWithClear(Intent intent) { ComponentName cn = intent.getComponent(); Intent mainIntent = IntentCompat.makeRestartActivityTask(cn); mContext.startActivity(mainIntent);/*from ww w . j a va2 s . c o m*/ try { ((Activity) mContext).finish(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.commonsware.android.sap.MainActivity.java
@Override public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { Toast.makeText(this, intent.getComponent().toString(), Toast.LENGTH_LONG).show(); return (false); }