List of usage examples for android.content.pm PackageManager getApplicationIcon
public abstract Drawable getApplicationIcon(String packageName) throws NameNotFoundException;
From source file:com.afwsamples.testdpc.EnableProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCheckinState = new CheckInState(this); if (savedInstanceState == null) { if (getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false)) { mCheckinState.setFirstAccountState(CheckInState.FIRST_ACCOUNT_STATE_READY); ProvisioningUtil.enableProfile(this); } else {/*from w ww.j a v a2 s . co m*/ // Set up an alarm to enable profile in case we do not receive first account ready // broadcast for whatever reason. FirstAccountReadyBroadcastReceiver.scheduleFirstAccountReadyTimeoutAlarm(this, WAIT_FOR_FIRST_ACCOUNT_READY_TIMEOUT); } } setContentView(R.layout.enable_profile_activity); mSetupWizardLayout = (SetupWizardLayout) findViewById(R.id.setup_wizard_layout); NavigationBar navigationBar = mSetupWizardLayout.getNavigationBar(); navigationBar.getBackButton().setEnabled(false); navigationBar.setNavigationBarListener(this); mFinishButton = navigationBar.getNextButton(); mFinishButton.setText(R.string.finish_button); mCheckInStateReceiver = new CheckInStateReceiver(); // This is just a user friendly shortcut to the policy management screen of this app. ImageView appIcon = (ImageView) findViewById(R.id.app_icon); TextView appLabel = (TextView) findViewById(R.id.app_label); try { PackageManager packageManager = getPackageManager(); ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0 /* Default flags */); appIcon.setImageDrawable(packageManager.getApplicationIcon(applicationInfo)); appLabel.setText(packageManager.getApplicationLabel(applicationInfo)); } catch (PackageManager.NameNotFoundException e) { Log.w("TestDPC", "Couldn't look up our own package?!?!", e); } // Show the user which account now has management, if specified. String addedAccount = getIntent().getStringExtra(LaunchIntentUtil.EXTRA_ACCOUNT_NAME); if (addedAccount != null) { View accountMigrationStatusLayout; if (isAccountMigrated(addedAccount)) { accountMigrationStatusLayout = findViewById(R.id.account_migration_success); } else { accountMigrationStatusLayout = findViewById(R.id.account_migration_fail); } accountMigrationStatusLayout.setVisibility(View.VISIBLE); TextView managedAccountName = (TextView) accountMigrationStatusLayout .findViewById(R.id.managed_account_name); managedAccountName.setText(addedAccount); } }
From source file:com.example.util.Utils.java
public static HashMap<String, Object> getApkInfo(Context context, File file) { PackageManager pm = context.getPackageManager(); String filePath = file.getAbsolutePath(); PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES); if (info == null) { return null; }/*from www . j a v a 2 s. co m*/ ApplicationInfo appInfo = info.applicationInfo; info.applicationInfo.sourceDir = filePath; info.applicationInfo.publicSourceDir = filePath; Drawable icon = pm.getApplicationIcon(appInfo); HashMap<String, Object> apk = new HashMap<String, Object>(); apk.put(Constants.KEY_PRODUCT_ICON, icon); apk.put(Constants.KEY_PRODUCT_NAME, file.getName()); apk.put(Constants.KEY_PRODUCT_INFO, filePath); apk.put(Constants.KEY_PRODUCT_DESCRIPTION, file.getAbsolutePath()); apk.put(Constants.KEY_PRODUCT_PAY_TYPE, Constants.PAY_TYPE_FREE); apk.put(Constants.KEY_PLACEHOLDER, false); return apk; }
From source file:org.sufficientlysecure.keychain.service.remote.AppSettingsFragment.java
private void setPackage(String packageName) { PackageManager pm = getActivity().getApplicationContext().getPackageManager(); // get application name and icon from package manager String appName = null;//from w w w .ja va 2 s . c o m Drawable appIcon = null; try { ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (final NameNotFoundException e) { // fallback appName = packageName; } mAppNameView.setText(appName); mAppIconView.setImageDrawable(appIcon); }
From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java
private void setMdmIcon(String packageName) { if (packageName != null) { PackageManager pm = getPackageManager(); try {/*from w ww. j a v a 2 s . c o m*/ ApplicationInfo ai = pm.getApplicationInfo(packageName, /* default flags */ 0); if (ai != null) { Drawable packageIcon = pm.getApplicationIcon(packageName); ImageView imageView = (ImageView) findViewById(R.id.mdm_icon_view); imageView.setImageDrawable(packageIcon); String appLabel = pm.getApplicationLabel(ai).toString(); TextView deviceManagerName = (TextView) findViewById(R.id.device_manager_name); deviceManagerName.setText(appLabel); } } catch (PackageManager.NameNotFoundException e) { // Package does not exist, ignore. Should never happen. ProvisionLogger.loge("Package does not exist. Should never happen."); } } }
From source file:com.cleanwiz.applock.ui.activity.AppLockActivity.java
private void checkLockInfos() { PackageManager pkgMgr = getPackageManager(); for (int i = lockInfos.size() - 1; i >= 0; i--) { CommLockInfo lock = lockInfos.get(i); ApplicationInfo appInfo = null;/*from w ww. jav a 2s . c om*/ try { appInfo = pkgMgr.getApplicationInfo(lock.getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES); } catch (NameNotFoundException e) { e.printStackTrace(); lockInfos.remove(lock); continue; } if (appInfo == null || pkgMgr.getApplicationIcon(appInfo) == null) { lockInfos.remove(lock); continue; } } }
From source file:edu.cmu.cylab.starslinger.view.ComposeFragment.java
@SuppressWarnings("deprecation") private void drawFileImage() { String filenameArray[] = mFilePath.split("\\."); String extension = filenameArray[filenameArray.length - 1]; String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mThumb != null && mThumb.length > 0) { ByteArrayInputStream in = new ByteArrayInputStream(mThumb); BitmapDrawable tn = new BitmapDrawable(in); mImageViewFile.setImageDrawable(tn); } else {/*from www . j ava 2 s . c om*/ Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setType(mime); PackageManager pm = getActivity().getPackageManager(); List<ResolveInfo> lract = pm.queryIntentActivities(viewIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for (ResolveInfo ri : lract) { if (!resolved) { try { Drawable icon = pm.getApplicationIcon(ri.activityInfo.packageName); mImageViewFile.setImageDrawable(icon); resolved = true; } catch (NameNotFoundException e) { mImageViewFile.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_file)); } } } } }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private boolean setView(int id, String packageName) { TextView donate = (TextView) findViewById(id); PackageManager pm = getPackageManager(); try {/*from www .j a v a 2 s . c o m*/ ApplicationInfo info = pm.getApplicationInfo(packageName, 0); if (!info.enabled) { return false; } CharSequence label = getLabel(pm, info); donate.setContentDescription(label); donate.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(pm.getApplicationIcon(info)), null, null); donate.setText(label); donate.setClickable(true); donate.setOnClickListener(this); donate.setVisibility(View.VISIBLE); return true; } catch (PackageManager.NameNotFoundException e) { UILog.d("cannot find package " + packageName, e); return false; } }
From source file:org.wso2.iot.agent.adapters.AppDrawerAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (appList != null) { View view;/*from w w w. j a va 2 s .com*/ if (convertView == null) { // inflating a new view only when necessary view = inflater.inflate(R.layout.kiosk_app_drawer, null); } else { view = convertView; } Holder holder = new Holder(); holder.appName = (TextView) view.findViewById(R.id.name); holder.appIcon = (ImageView) view.findViewById(R.id.icon); PackageManager pm = context.getPackageManager(); String packageName = appList.get(position); if (packageName.equals(NEW_APP)) { holder.appName.setText(NEW_APP); holder.appIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_download)); } else { ApplicationInfo applicationInfo = null; try { applicationInfo = pm.getApplicationInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } holder.appName.setText(pm.getApplicationLabel(applicationInfo).toString()); try { holder.appIcon.setImageDrawable(pm.getApplicationIcon(packageName)); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } } return view; } else { return null; } }
From source file:com.leec.tools.apps.DetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_details_pager); // Set up the action bar. final android.support.v7.app.ActionBar actionBar = this.getSupportActionBar(); Intent intent = getIntent();/* www. j a v a 2s. c o m*/ String packageName = intent.getStringExtra(ARG_PACKAGE_NAME); PackageManager pm = getPackageManager(); if (actionBar != null) { //show icon false //actionBar.setDisplayShowHomeEnabled(false); //back action actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setSubtitle(packageName); try { PackageInfo p = pm.getPackageInfo(packageName, 0); actionBar.setTitle(pm.getApplicationLabel(p.applicationInfo)); actionBar.setIcon(pm.getApplicationIcon(p.applicationInfo)); } catch (NameNotFoundException e) { } } // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(), packageName, this); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.app_details_pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); PagerTabStrip tabStrip = (PagerTabStrip) mViewPager.findViewById(R.id.pager_title); //tabStrip.setTabIndicatorColor(); tabStrip.setTabIndicatorColorResource(R.color.tab_indicator_color); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.polyvi.xface.extension.XAppExt.java
/** * ???/*from w ww.j ava 2 s . c om*/ * * @param type * "0":"1","2": * @return ?? * @throws JSONException */ public JSONArray queryInstalledNativeApp(String type) throws JSONException { JSONArray appArray = new JSONArray(); int appType = Integer.valueOf(type); PackageManager pm = getContext().getPackageManager(); List<PackageInfo> packages = pm.getInstalledPackages(0); for (PackageInfo packageInfo : packages) { if (getContext().getPackageName().equals(packageInfo.applicationInfo.packageName)) continue; switch (appType) { case 0: JSONObject obj = new JSONObject(); obj.put(TAG_APP_NAME, pm.getApplicationLabel(packageInfo.applicationInfo).toString()); obj.put(TAG_APP_ID, packageInfo.applicationInfo.packageName); obj.put(TAG_APP_ICON, drawableToBase64(pm.getApplicationIcon(packageInfo.applicationInfo))); appArray.put(obj); break; case 1: if ((packageInfo.applicationInfo.flags & 0x1) != 0) continue; JSONObject userAppObj = new JSONObject(); userAppObj.put(TAG_APP_NAME, pm.getApplicationLabel(packageInfo.applicationInfo).toString()); userAppObj.put(TAG_APP_ID, packageInfo.applicationInfo.packageName); userAppObj.put(TAG_APP_ICON, drawableToBase64(pm.getApplicationIcon(packageInfo.applicationInfo))); appArray.put(userAppObj); break; case 2: if ((packageInfo.applicationInfo.flags & 0x1) == 0) continue; JSONObject sysAppObj = new JSONObject(); sysAppObj.put(TAG_APP_NAME, pm.getApplicationLabel(packageInfo.applicationInfo).toString()); sysAppObj.put(TAG_APP_ID, packageInfo.applicationInfo.packageName); sysAppObj.put(TAG_APP_ICON, drawableToBase64(pm.getApplicationIcon(packageInfo.applicationInfo))); appArray.put(sysAppObj); } } return appArray; }