List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StartJavaPrg(String[] sArgs, Intent preIntent) { String sRet = ""; String sArgList = ""; String sUrl = ""; // String sRedirFileName = ""; Intent prgIntent = null;/*w ww .j av a2 s . c o m*/ Context ctx = contextWrapper.getApplicationContext(); PackageManager pm = ctx.getPackageManager(); if (preIntent == null) prgIntent = new Intent(); else prgIntent = preIntent; prgIntent.setPackage(sArgs[0]); prgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Get the main activity for this package try { final ComponentName c = pm.getLaunchIntentForPackage(sArgs[0]).getComponent(); prgIntent.setClassName(c.getPackageName(), c.getClassName()); } catch (Exception e) { e.printStackTrace(); return "Unable to find main activity for package: " + sArgs[0]; } if (sArgs.length > 1) { if (sArgs[0].contains("android.browser")) prgIntent.setAction(Intent.ACTION_VIEW); else prgIntent.setAction(Intent.ACTION_MAIN); if (sArgs[0].contains("fennec") || sArgs[0].contains("firefox")) { sArgList = ""; sUrl = ""; for (int lcv = 1; lcv < sArgs.length; lcv++) { if (sArgs[lcv].contains("://")) { prgIntent.setAction(Intent.ACTION_VIEW); sUrl = sArgs[lcv]; } else { if (sArgs[lcv].equals(">")) { lcv++; if (lcv < sArgs.length) lcv++; // sRedirFileName = sArgs[lcv++]; } else sArgList += " " + sArgs[lcv]; } } if (sArgList.length() > 0) prgIntent.putExtra("args", sArgList.trim()); if (sUrl.length() > 0) prgIntent.setData(Uri.parse(sUrl.trim())); } else { for (int lcv = 1; lcv < sArgs.length; lcv++) sArgList += " " + sArgs[lcv]; prgIntent.setData(Uri.parse(sArgList.trim())); } } else { prgIntent.setAction(Intent.ACTION_MAIN); } try { contextWrapper.startActivity(prgIntent); FindProcThread findProcThrd = new FindProcThread(contextWrapper, sArgs[0]); findProcThrd.start(); findProcThrd.join(7000); if (!findProcThrd.bFoundIt && !findProcThrd.bStillRunning) { sRet = "Unable to start " + sArgs[0] + ""; } } catch (ActivityNotFoundException anf) { anf.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } ctx = null; return (sRet); }
From source file:com.android.launcher2.Launcher.java
void startApplicationDetailsActivity(ComponentName componentName) { String packageName = componentName.getPackageName(); Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); startActivitySafely(null, intent, "startApplicationDetailsActivity"); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String TopActivity() { String sRet = ""; ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = null; ComponentName componentInfo = null; if (aMgr != null) { taskInfo = aMgr.getRunningTasks(1); }/* w ww . java 2s . c o m*/ if (taskInfo != null) { // topActivity: "The activity component at the top of the history stack of the task. // This is what the user is currently doing." componentInfo = taskInfo.get(0).topActivity; } if (componentInfo != null) { sRet = componentInfo.getPackageName(); } return (sRet); }
From source file:com.android.launcher2.Workspace.java
void removeItems(final ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);// w w w . j a v a2 s . co m ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (final CellLayout layoutParent : cellLayouts) { final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); // Avoid ANRs by treating each screen separately post(new Runnable() { public void run() { final ArrayList<View> childrenToRemove = new ArrayList<View>(); childrenToRemove.clear(); int childCount = layout.getChildCount(); for (int j = 0; j < childCount; j++) { final View view = layout.getChildAt(j); Object tag = view.getTag(); if (tag instanceof ShortcutInfo) { final ShortcutInfo info = (ShortcutInfo) tag; final Intent intent = info.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } else if (tag instanceof FolderInfo) { final FolderInfo info = (FolderInfo) tag; final ArrayList<ShortcutInfo> contents = info.contents; final int contentsCount = contents.size(); final ArrayList<ShortcutInfo> appsToRemoveFromFolder = new ArrayList<ShortcutInfo>(); for (int k = 0; k < contentsCount; k++) { final ShortcutInfo appInfo = contents.get(k); final Intent intent = appInfo.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { appsToRemoveFromFolder.add(appInfo); } } } for (ShortcutInfo item : appsToRemoveFromFolder) { info.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } } else if (tag instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; final ComponentName provider = info.providerName; if (provider != null) { if (packageNames.contains(provider.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } } childCount = childrenToRemove.size(); for (int j = 0; j < childCount; j++) { View child = childrenToRemove.get(j); // Note: We can not remove the view directly from CellLayoutChildren as this // does not re-mark the spaces as unoccupied. layoutParent.removeViewInLayout(child); if (child instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) child); } } if (childCount > 0) { layout.requestLayout(); layout.invalidate(); } } }); } // Clean up new-apps animation list final Context context = getContext(); post(new Runnable() { @Override public void run() { String spKey = LauncherApplication.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null); // Remove all queued items that match the same package if (newApps != null) { synchronized (newApps) { Iterator<String> iter = newApps.iterator(); while (iter.hasNext()) { try { Intent intent = Intent.parseUri(iter.next(), 0); String pn = ItemInfo.getPackageName(intent); if (packageNames.contains(pn)) { iter.remove(); } // It is possible that we've queued an item to be loaded, yet it has // not been added to the workspace, so remove those items as well. ArrayList<ItemInfo> shortcuts; shortcuts = LauncherModel.getWorkspaceShortcutItemInfosWithIntent(intent); for (ItemInfo info : shortcuts) { LauncherModel.deleteItemFromDatabase(context, info); } } catch (URISyntaxException e) { } } } } } }); }
From source file:com.android.launcher2.Launcher.java
/** * Event handler for the voice button//from ww w.j a v a 2 s . co m * * @param v The view that was clicked. */ public void onClickVoiceButton(View v) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); try { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }
From source file:com.android.launcher2.Launcher.java
private boolean updateVoiceSearchIcon(boolean searchVisible) { final View voiceButtonContainer = findViewById(R.id.voice_button_container); final View voiceButton = findViewById(R.id.voice_button); final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); // We only show/update the voice search icon if the search icon is enabled as well final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); ComponentName activityName = null;// w w w .jav a 2 s . c o m if (globalSearchActivity != null) { // Check if the global search activity handles voice search Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setPackage(globalSearchActivity.getPackageName()); activityName = intent.resolveActivity(getPackageManager()); } if (activityName == null) { // Fallback: check if an activity other than the global search activity // resolves this Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); activityName = intent.resolveActivity(getPackageManager()); } if (searchVisible && activityName != null) { int coi = getCurrentOrientationIndexForGlobalIcons(); sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); if (sVoiceSearchIcon[coi] == null) { sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_ICON_METADATA_NAME); } if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); voiceButton.setVisibility(View.VISIBLE); if (voiceButtonProxy != null) { voiceButtonProxy.setVisibility(View.VISIBLE); } invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); return true; } else { if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); voiceButton.setVisibility(View.GONE); if (voiceButtonProxy != null) { voiceButtonProxy.setVisibility(View.GONE); } return false; } }
From source file:cc.flydev.launcher.Workspace.java
void removeItemsByPackageName(final ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);/* w w w .j a v a 2s . c o m*/ // Filter out all the ItemInfos that this is going to affect final HashSet<ItemInfo> infos = new HashSet<ItemInfo>(); final HashSet<ComponentName> cns = new HashSet<ComponentName>(); ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (CellLayout layoutParent : cellLayouts) { ViewGroup layout = layoutParent.getShortcutsAndWidgets(); int childCount = layout.getChildCount(); for (int i = 0; i < childCount; ++i) { View view = layout.getChildAt(i); infos.add((ItemInfo) view.getTag()); } } LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { @Override public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { if (packageNames.contains(cn.getPackageName())) { cns.add(cn); return true; } return false; } }; LauncherModel.filterItemInfos(infos, filter); // Remove the affected components removeItemsByComponentName(cns); }
From source file:com.aidy.launcher3.ui.workspace.Workspace.java
public void removeItemsByPackageName(final ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);/*from ww w. j a va 2s . c o m*/ // Filter out all the ItemInfos that this is going to affect final HashSet<ItemInfoBean> infos = new HashSet<ItemInfoBean>(); final HashSet<ComponentName> cns = new HashSet<ComponentName>(); ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (CellLayout layoutParent : cellLayouts) { ViewGroup layout = layoutParent.getShortcutsAndWidgets(); int childCount = layout.getChildCount(); for (int i = 0; i < childCount; ++i) { View view = layout.getChildAt(i); infos.add((ItemInfoBean) view.getTag()); } } LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { @Override public boolean filterItem(ItemInfoBean parent, ItemInfoBean info, ComponentName cn) { if (packageNames.contains(cn.getPackageName())) { cns.add(cn); return true; } return false; } }; LauncherModel.filterItemInfos(infos, filter); // Remove the affected components removeItemsByComponentName(cns); }
From source file:com.klinker.android.launcher.launcher3.Workspace.java
public void disableShortcutsByPackageName(final ArrayList<String> packages, final UserHandleCompat user, final int reason) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);//from w w w .j ava 2 s . com mapOverItems(MAP_RECURSE, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View v, View parent) { if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { ShortcutInfo shortcutInfo = (ShortcutInfo) info; ComponentName cn = shortcutInfo.getTargetComponent(); if (user.equals(shortcutInfo.user) && cn != null && packageNames.contains(cn.getPackageName())) { shortcutInfo.isDisabled |= reason; BubbleTextView shortcut = (BubbleTextView) v; shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache); if (parent != null) { parent.invalidate(); } } } // process all the shortcuts return false; } }); }
From source file:xyz.klinker.blur.launcher3.Workspace.java
void removeItemsByPackageName(final HashSet<String> packageNames, final UserHandleCompat user) { // Filter out all the ItemInfos that this is going to affect final HashSet<ItemInfo> infos = new HashSet<ItemInfo>(); final HashSet<ComponentName> cns = new HashSet<ComponentName>(); ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (CellLayout layoutParent : cellLayouts) { ViewGroup layout = layoutParent.getShortcutsAndWidgets(); int childCount = layout.getChildCount(); for (int i = 0; i < childCount; ++i) { View view = layout.getChildAt(i); infos.add((ItemInfo) view.getTag()); }/* w ww .j a va2 s . com*/ } LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { @Override public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { if (packageNames.contains(cn.getPackageName()) && info.user.equals(user)) { cns.add(cn); return true; } return false; } }; LauncherModel.filterItemInfos(infos, filter); // Remove the affected components removeItemsByComponentName(cns, user); }