本文整理匯總了Java中android.view.ContextMenu.addSubMenu方法的典型用法代碼示例。如果您正苦於以下問題:Java ContextMenu.addSubMenu方法的具體用法?Java ContextMenu.addSubMenu怎麽用?Java ContextMenu.addSubMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.addSubMenu方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreateContextMenu
import android.view.ContextMenu; //導入方法依賴的package包/類
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
// Check if running
boolean running = false;
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
for (RunningAppProcessInfo info : activityManager.getRunningAppProcesses())
if (info.uid == mAppInfo.getUid())
running = true;
PackageManager pm = getPackageManager();
List<String> listPackageNames = mAppInfo.getPackageName();
List<String> listApplicationName = mAppInfo.getApplicationName();
for (int i = 0; i < listPackageNames.size(); i++) {
Menu appMenu = (listPackageNames.size() == 1) ? menu : menu.addSubMenu(i, Menu.NONE, Menu.NONE,
listApplicationName.get(i));
// Launch
MenuItem launch = appMenu.add(i, MENU_LAUNCH, Menu.NONE, getString(R.string.menu_app_launch));
if (pm.getLaunchIntentForPackage(listPackageNames.get(i)) == null)
launch.setEnabled(false);
// Settings
appMenu.add(i, MENU_SETTINGS, Menu.NONE, getString(R.string.menu_app_settings));
// Kill
MenuItem kill = appMenu.add(i, MENU_KILL, Menu.NONE, getString(R.string.menu_app_kill));
kill.setEnabled(running && PrivacyManager.isApplication(mAppInfo.getUid()));
// Play store
MenuItem store = appMenu.add(i, MENU_STORE, Menu.NONE, getString(R.string.menu_app_store));
if (!Util.hasMarketLink(this, listPackageNames.get(i)))
store.setEnabled(false);
}
}