List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:org.droid2droid.ui.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.main_fragment_menu, menu); // Share menu try {/*from www .j av a2 s. c o m*/ MenuItem item = menu.findItem(R.id.share); PackageManager pm = getPackageManager(); ApplicationInfo info = pm.getApplicationInfo(getPackageName(), 0); Intent shareIntent = new Intent(Intent.ACTION_SEND) .putExtra(Intent.EXTRA_SUBJECT, pm.getText(getPackageName(), info.labelRes, info)) .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(info.sourceDir))) // .setType("application/vnd.android.package-archive"); .setType("*/*") // Android >3.x refuse to download apk // .setType("image/jpeg") ; ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider(); shareActionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); shareActionProvider.setShareIntent(shareIntent); } catch (NameNotFoundException e) { // Ignore if (E) Log.e(TAG_INSTALL, "Impossible to share RemoteAndroid"); } return true; }
From source file:org.whispersystems.libpastelog.SubmitLogFragment.java
private static String buildDescription(Context context) { final PackageManager pm = context.getPackageManager(); final StringBuilder builder = new StringBuilder(); builder.append("Device : ").append(Build.MANUFACTURER).append(" ").append(Build.MODEL).append(" (") .append(Build.PRODUCT).append(")\n"); builder.append("Android : ").append(VERSION.RELEASE).append(" (").append(VERSION.INCREMENTAL).append(", ") .append(Build.DISPLAY).append(")\n"); builder.append("Memory : ").append(getMemoryUsage(context)).append("\n"); builder.append("Memclass: ").append(getMemoryClass(context)).append("\n"); builder.append("OS Host : ").append(Build.HOST).append("\n"); builder.append("App : "); try {//from ww w. j a va2s .c o m builder.append(pm.getApplicationLabel(pm.getApplicationInfo(context.getPackageName(), 0))).append(" ") .append(pm.getPackageInfo(context.getPackageName(), 0).versionName).append("\n"); } catch (PackageManager.NameNotFoundException nnfe) { builder.append("Unknown\n"); } return builder.toString(); }
From source file:org.sufficientlysecure.keychain.remote.ui.AppSettingsFragment.java
private void updateView(AppSettings appSettings) { // get application name and icon from package manager String appName;//w ww . ja v a 2 s . c o m Drawable appIcon = null; PackageManager pm = getActivity().getApplicationContext().getPackageManager(); try { ApplicationInfo ai = pm.getApplicationInfo(appSettings.getPackageName(), 0); appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (NameNotFoundException e) { // fallback appName = appSettings.getPackageName(); } mAppNameView.setText(appName); mAppIconView.setImageDrawable(appIcon); // advanced info: package name mPackageName.setText(appSettings.getPackageName()); // advanced info: package signature SHA-256 try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(appSettings.getPackageSignature()); byte[] digest = md.digest(); String signature = new String(Hex.encode(digest)); mPackageSignature.setText(signature); } catch (NoSuchAlgorithmException e) { Log.e(Constants.TAG, "Should not happen!", e); } }
From source file:org.sufficientlysecure.keychain.remote.ui.AppSettingsHeaderFragment.java
private void updateView(AppSettings appSettings) { // get application name and icon from package manager String appName;/*from w w w . ja v a 2 s. co m*/ Drawable appIcon = null; PackageManager pm = getActivity().getApplicationContext().getPackageManager(); try { ApplicationInfo ai = pm.getApplicationInfo(appSettings.getPackageName(), 0); appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (NameNotFoundException e) { // fallback appName = appSettings.getPackageName(); } mAppNameView.setText(appName); mAppIconView.setImageDrawable(appIcon); // advanced info: package name mPackageName.setText(appSettings.getPackageName()); // advanced info: package signature SHA-256 try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(appSettings.getPackageCertificate()); byte[] digest = md.digest(); String signature = new String(Hex.encode(digest)); mPackageCertificate.setText(signature); } catch (NoSuchAlgorithmException e) { Log.e(Constants.TAG, "Should not happen!", e); } }
From source file:com.example.android.apprestrictionenforcer.StatusFragment.java
private void updateUi(Activity activity) { PackageManager packageManager = activity.getPackageManager(); try {/*from www . j a v a 2s.co m*/ ApplicationInfo info = packageManager.getApplicationInfo(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity .getSystemService(Activity.DEVICE_POLICY_SERVICE); if ((info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { if (!devicePolicyManager.isApplicationHidden(EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is ready to enforce restrictions // This is unlikely to happen in this sample as unhideApp() handles it. mListener.onStatusUpdated(); } else { // The app is installed but hidden in this profile mTextStatus.setText(R.string.status_not_activated); mButtonUnhide.setVisibility(View.VISIBLE); } } else { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } } catch (PackageManager.NameNotFoundException e) { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } }
From source file:com.noshufou.android.su.util.Util.java
public static Drawable getAppIcon(Context c, int uid) { PackageManager pm = c.getPackageManager(); Drawable appIcon = c.getResources().getDrawable(R.drawable.sym_def_app_icon); String[] packages = pm.getPackagesForUid(uid); if (packages != null) { // if (packages.length == 1) { try {//w w w. ja va 2 s .c om ApplicationInfo appInfo = pm.getApplicationInfo(packages[0], 0); appIcon = pm.getApplicationIcon(appInfo); } catch (NameNotFoundException e) { Log.e(TAG, "No package found matching with the uid " + uid); } // } } else { Log.e(TAG, "Package not found for uid " + uid); } return appIcon; }
From source file:android_network.hetnet.vpn_service.Util.java
public static List<String> getApplicationNames(int uid, Context context) { List<String> listResult = new ArrayList<>(); if (uid == 0) listResult.add(context.getString(R.string.title_root)); else if (uid == 1013) listResult.add(context.getString(R.string.title_mediaserver)); else if (uid == 9999) listResult.add(context.getString(R.string.title_nobody)); else {/* w w w. j av a2 s . c o m*/ PackageManager pm = context.getPackageManager(); String[] pkgs = pm.getPackagesForUid(uid); if (pkgs == null) listResult.add(Integer.toString(uid)); else for (String pkg : pkgs) try { ApplicationInfo info = pm.getApplicationInfo(pkg, 0); listResult.add(pm.getApplicationLabel(info).toString()); } catch (PackageManager.NameNotFoundException ignored) { } Collections.sort(listResult); } return listResult; }
From source file:com.github.pennyfive.sqlitestudio.ui.PackagesFragment.java
private String getApplicationName(String packageName) { try {/*from w ww.ja v a 2 s. co m*/ PackageManager pm = getActivity().getPackageManager(); return (String) pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)); } catch (NameNotFoundException e) { return ""; } }
From source file:com.oprisnik.semdroid.AnalysisResultsListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAdapter = new ExpandableResultsAdapter(getActivity()); setListAdapter(mAdapter);/*from ww w . j a va2 s. com*/ mCache = SemdroidReportCache.getInstance(getActivity().getSupportFragmentManager()); mPackage = getActivity().getIntent().getStringExtra(AnalysisResultsOverviewFragment.KEY_PACKAGE_NAME); String[] plugins = getActivity().getIntent().getStringArrayExtra(KEY_PLUGINS); if (plugins != null) { mPlugins = new HashSet<String>(); for (String s : plugins) { mPlugins.add(s); } } try { PackageManager pm = getActivity().getPackageManager(); mAppInfo = pm.getApplicationInfo(mPackage, 0); } catch (Exception e) { Toast.makeText(getActivity(), "Error: Application " + mPackage + " not installed!", Toast.LENGTH_SHORT) .show(); getActivity().finish(); } String key; if (getActivity().getIntent().hasExtra(AnalysisIntentService.KEY_RESULTS_KEY)) { key = getActivity().getIntent().getStringExtra(AnalysisIntentService.KEY_RESULTS_KEY); } else { key = AnalysisIntentService.getResultsKey(mPackage); } mAnalysisReport = mCache.get(key); if (mAnalysisReport == null) { // start analysis Intent msgIntent = new Intent(getActivity(), AnalysisIntentService.class); msgIntent.putExtra(AnalysisIntentService.KEY_PACKAGE_NAME, mPackage); getActivity().startService(msgIntent); } else { handleResults(mAnalysisReport); } }
From source file:org.microg.gms.ui.GcmRegisteredAppsFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { GcmData.AppInfo appInfo = appsAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position); MenuInflater menuInflater = getActivity().getMenuInflater(); menuInflater.inflate(R.menu.gcm_app, menu); PackageManager packageManager = getContext().getPackageManager(); try {//from ww w . j a va 2s . c o m ApplicationInfo applicationInfo = packageManager.getApplicationInfo(appInfo.app, 0); menu.setHeaderTitle(packageManager.getApplicationLabel(applicationInfo)); } catch (PackageManager.NameNotFoundException e) { menu.setHeaderTitle(appInfo.app); } }