List of usage examples for android.content.pm ApplicationInfo loadLabel
public @NonNull CharSequence loadLabel(@NonNull PackageManager pm)
From source file:com.rp.podemu.MainActivity.java
private void loadPreferences() { try {/*ww w. j a va 2 s .c o m*/ ImageView appLogo = (ImageView) findViewById(R.id.CTRL_app_icon); SharedPreferences sharedPref = this.getSharedPreferences("PODEMU_PREFS", Context.MODE_PRIVATE); ctrlAppProcessName = sharedPref.getString("ControlledAppProcessName", "unknown app"); String enableDebug = sharedPref.getString("enableDebug", "false"); Boolean ctrlAppUpdated = sharedPref.getBoolean("ControlledAppUpdated", false); if (PodEmuMediaStore.getInstance() == null) { PodEmuMediaStore.initialize(this); } // update ctrlApp only if it was changed or MediaPlayback engine is not yet initialized if (ctrlAppUpdated || MediaPlayback.getInstance() == null) { PodEmuMediaStore.getInstance().setCtrlAppProcessName(ctrlAppProcessName); } if (enableDebug.equals("true")) PodEmuLog.DEBUG_LEVEL = 2; else PodEmuLog.DEBUG_LEVEL = 0; if (podEmuService != null) { podEmuService.reloadBaudRate(); } if (MediaPlayback.getInstance() != null) { currentlyPlaying.bulk_update( MediaPlayback.getInstance().getCurrentPlaylist().getCurrentTrack().toPodEmuMessage()); updateCurrentlyPlayingDisplay(); } PackageManager pm = getPackageManager(); ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(ctrlAppProcessName, PackageManager.GET_META_DATA); ctrlAppStatusTitle.setText("Controlled app: " + appInfo.loadLabel(pm)); ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0xff, 0xff)); if (ctrlAppUpdated && currentlyPlaying.isPlaying()) { // invoke play_pause button to switch the app MediaPlayback mediaPlayback = MediaPlayback.getInstance(); mediaPlayback.action_play_pause(); } SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("ControlledAppUpdated", false); editor.apply(); appLogo.setImageDrawable(appInfo.loadIcon(pm)); } catch (PackageManager.NameNotFoundException e) { ctrlAppStatusTitle.setText("Please go to the settings and setup controlled music application"); ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0x00, 0x00)); appLogo.setImageDrawable(ContextCompat.getDrawable(this, (R.drawable.questionmark))); } } catch (Exception e) { PodEmuLog.printStackTrace(e); throw e; } }
From source file:org.namelessrom.devicecontrol.appmanager.AppDetailsActivity.java
private void setupPermissionsView() { final LinearLayout permissionsView = (LinearLayout) findViewById(R.id.permissions_section); final boolean unsupported = Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN; if (unsupported) { permissionsView.setVisibility(View.GONE); return;/*from w w w .j a va2 s . co m*/ } AppSecurityPermissions asp = new AppSecurityPermissions(this, mAppItem.getPackageName()); // Make the security sections header visible LinearLayout securityList = (LinearLayout) findViewById(R.id.security_settings_list); securityList.removeAllViews(); securityList.addView(asp.getPermissionsView()); // If this app is running under a shared user ID with other apps, // update the description to explain this. String[] packages = mPm.getPackagesForUid(mAppItem.getApplicationInfo().uid); if (packages != null && packages.length > 1) { final ArrayList<CharSequence> pnames = new ArrayList<>(); for (final String pkg : packages) { if (mAppItem.getPackageName().equals(pkg)) { continue; } try { ApplicationInfo ainfo = mPm.getApplicationInfo(pkg, 0); pnames.add(ainfo.loadLabel(mPm)); } catch (PackageManager.NameNotFoundException ignored) { } } final int N = pnames.size(); if (N > 0) { final Resources res = getResources(); String appListStr; if (N == 1) { appListStr = pnames.get(0).toString(); } else if (N == 2) { appListStr = res.getString(R.string.join_two_items, pnames.get(0), pnames.get(1)); } else { appListStr = pnames.get(N - 2).toString(); for (int i = N - 3; i >= 0; i--) { appListStr = res.getString( i == 0 ? R.string.join_many_items_first : R.string.join_many_items_middle, pnames.get(i), appListStr); } appListStr = res.getString(R.string.join_many_items_last, appListStr, pnames.get(N - 1)); } final TextView descr = (TextView) findViewById(R.id.security_settings_desc); descr.setText(res.getString(R.string.security_settings_desc_multi, mAppItem.getApplicationInfo().loadLabel(mPm), appListStr)); } } }
From source file:com.github.michalbednarski.intentslab.browser.ApplicationFetcher.java
@Override Object getEntries(Context context) { PackageManager pm = context.getPackageManager(); int requestedPackageInfoFlags = PackageManager.GET_DISABLED_COMPONENTS | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0); List<PackageInfo> allPackages = pm.getInstalledPackages(requestedPackageInfoFlags); ArrayList<Component> selectedApps = new ArrayList<Component>(); for (PackageInfo pack : allPackages) { ApplicationInfo applicationInfo = pack.applicationInfo; // Filter out non-applications if (applicationInfo == null) { continue; }/*from w ww . j a v a 2 s . c o m*/ // System app filter if ((((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER) & appType) == 0) { continue; } // Metadata filter if (!checkMetaDataFilter(applicationInfo)) { continue; } // Build and add app descriptor Component app = new Component(); app.title = String.valueOf(applicationInfo.loadLabel(pm)); app.subtitle = pack.packageName; app.componentInfo = applicationInfo; selectedApps.add(app); // Allow cancelling task if (Thread.interrupted()) { return null; } } return selectedApps.toArray(new Component[selectedApps.size()]); }
From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME); PackageManager pm = getPackageManager(); ApplicationInfo appInfo; try {//from w ww . j ava 2s . co m //noinspection WrongConstant (lint is actually wrong here!) appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Failed to get ApplicationInfo for uninstalling"); } final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; if (isSystem && !isUpdate) { // Cannot remove system apps unless we're uninstalling updates throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates"); } int messageId; if (isUpdate) { messageId = R.string.uninstall_update_confirm; } else { messageId = R.string.uninstall_confirm; } // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final AlertDialog.Builder builder = new AlertDialog.Builder(theme); builder.setTitle(appInfo.loadLabel(pm)); builder.setIcon(appInfo.loadIcon(pm)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent data = new Intent(); data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName); setResult(Activity.RESULT_OK, intent); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setMessage(messageId); builder.create().show(); }
From source file:com.savor.ads.core.Session.java
private void getApplicationInfo() { final PackageManager pm = mContext.getPackageManager(); try {/*from w w w .ja va2s.c o m*/ final PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0); versionName = pi.versionName; versionCode = pi.versionCode; final ApplicationInfo ai = pm.getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA); debugType = "1";// ai.metaData.get("app_debug").toString(); if ("1".equals(debugType)) { // developer mode isDebug = true; } else if ("0".equals(debugType)) { // release mode isDebug = false; } LogUtils.allow = isDebug; appName = String.valueOf(ai.loadLabel(pm)); LogUtils.appTagPrefix = appName; } catch (NameNotFoundException e) { LogUtils.d("met some error when get application info"); } }