List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:com.nagopy.android.mypkgs.model.loader.ApplicationIconLoader.java
/** * ???.<br>// ww w . java 2 s . c om * ????????? * * @param params ??????? * @return ??????? */ @Override protected AppData doInBackground(AppData... params) { TextView textView = textViewWeakReference.get(); if (textView == null) { return null; } AppData appData = params[0]; PackageManager packageManager = context.getPackageManager(); DebugUtil.verboseLog("doInBackground :" + appData.packageName); if (appData.icon != null && appData.icon.get() != null) { DebugUtil.verboseLog("use cache icon :" + appData.packageName); return appData; } try { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(appData.packageName, RETRIEVE_FLAGS); Drawable icon; if (applicationInfo.icon == 0x0) { DebugUtil.verboseLog(appData.packageName + ", icon=0x0"); icon = getDefaultIcon(context); } else { icon = applicationInfo.loadIcon(packageManager); } appData.icon = new WeakReference<>(icon); DebugUtil.verboseLog("load icon complete :" + appData.packageName); return appData; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("ApplicationInfo??? packageName=" + appData.packageName, e); } }
From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java
private void setMdmIcon(String packageName) { if (packageName != null) { PackageManager pm = getPackageManager(); try {/*from ww w .j a v a 2 s. com*/ 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:de.schildbach.wallet.ui.ChannelRequestActivity.java
private void initWithBinder() { // Figure out the caller of this activity. PackageManager packageManager = getApplicationContext().getPackageManager(); final String callingPackage = getCallingPackage(); try {//from www . ja v a 2s . co m ApplicationInfo appInfo = packageManager.getApplicationInfo(callingPackage, 0); requestingApp = packageManager.getApplicationLabel(appInfo); } catch (PackageManager.NameNotFoundException e) { // Fall through. } if (requestingApp == null) requestingApp = "unknown"; // TODO: Show the user how much the app can still spend, maybe even how much it has spent long amountLeft = service.getAppValueRemaining(callingPackage); appSpecifiedMinValue = appSpecifiedMinValue - amountLeft; requestedValueStr = GenericUtils.formatValue(BigInteger.valueOf(appSpecifiedMinValue), Constants.BTC_MAX_PRECISION) + " " + Constants.CURRENCY_CODE_BITCOIN; final String intro = getString(R.string.channel_request_intro, requestingApp, requestedValueStr, ""); final TextView label = (TextView) findViewById(R.id.channel_request_intro_text); label.setText(intro); btcAmountView.setAmount(BigInteger.valueOf(appSpecifiedMinValue), true); acceptButton.setEnabled(true); }
From source file:com.tsroad.map.poisearch.PoiKeywordSearchActivity.java
/** * ??app??/*w ww. j a v a 2s .c o m*/ */ public String getApplicationName() { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try { packageManager = getApplicationContext().getPackageManager(); applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); return applicationName; }
From source file:fm.feed.android.SampleApp.fragment.TestFragment.java
private void updateTitle(PlayInfo playInfo) { final PackageManager pm = getActivity().getApplicationContext().getPackageManager(); ApplicationInfo ai;// w ww . j a v a 2 s.co m try { ai = pm.getApplicationInfo(getActivity().getPackageName(), 0); } catch (final PackageManager.NameNotFoundException e) { ai = null; } final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)"); getActivity().setTitle(applicationName + " (sdk: " + playInfo.getSdkVersion() + ")"); }
From source file:com.tundem.aboutlibraries.ui.LibsFragment.java
private void generateAboutThisAppSection() { if (aboutShowIcon != null && aboutShowVersion != null) { View headerView = getActivity().getLayoutInflater().inflate(R.layout.listheader_opensource, null); //get the about this app views ImageView aboutIcon = (ImageView) headerView.findViewById(R.id.aboutIcon); TextView aboutVersion = (TextView) headerView.findViewById(R.id.aboutVersion); View aboutDivider = headerView.findViewById(R.id.aboutDivider); TextView aboutAppDescription = (TextView) headerView.findViewById(R.id.aboutDescription); //get the packageManager to load and read some values :D PackageManager pm = getActivity().getPackageManager(); //get the packageName String packageName = getActivity().getPackageName(); //Try to load the applicationInfo ApplicationInfo appInfo = null;/* ww w. jav a 2 s.c om*/ PackageInfo packageInfo = null; try { appInfo = pm.getApplicationInfo(packageName, 0); packageInfo = pm.getPackageInfo(packageName, 0); } catch (Exception ex) { } //Set the Icon or hide it if (aboutShowIcon && appInfo != null) { aboutIcon.setImageDrawable(appInfo.loadIcon(pm)); } else { aboutIcon.setVisibility(View.GONE); } //set the Version or hide it if (aboutShowVersion && packageInfo != null) { String versionName = packageInfo.versionName; int versionCode = packageInfo.versionCode; aboutVersion.setText(getString(R.string.version) + " " + versionName + " (" + versionCode + ")"); } else { aboutVersion.setVisibility(View.GONE); } //Set the description or hide it if (!TextUtils.isEmpty(aboutDescription)) { aboutAppDescription.setText(aboutDescription); } else { aboutAppDescription.setVisibility(View.GONE); } //if there is no description or no icon and version number hide the divider if (!aboutShowIcon && !aboutShowVersion || TextUtils.isEmpty(aboutDescription)) { aboutDivider.setVisibility(View.GONE); } //add this cool thing to the headerView of our listView listView.addHeaderView(headerView, null, false); } }
From source file:com.rp.podemu.SettingsActivity.java
private void setCtrlApplicationInfo() { String processName = sharedPref.getString("ControlledAppProcessName", "unknown application"); PackageManager pm = getPackageManager(); ApplicationInfo appInfo;/*from w ww.j a va2 s .c o m*/ TextView textView = (TextView) findViewById(R.id.ctrlAppName); try { appInfo = pm.getApplicationInfo(processName, PackageManager.GET_META_DATA); textView.setText(appInfo.loadLabel(pm)); ImageView imageView = (ImageView) findViewById(R.id.ctrlAppIcon); imageView.setImageDrawable(appInfo.loadIcon(pm)); } catch (PackageManager.NameNotFoundException e) { textView.setText("Cannot load application "); } }
From source file:com.samsung.richnotification.RichNotification.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); String mPackageName = cordova.getActivity().getPackageName(); PackageManager pm = cordova.getActivity().getPackageManager(); try {// w w w.j a v a2s . c o m ApplicationInfo ai = pm.getApplicationInfo(mPackageName, PackageManager.GET_META_DATA); if (ai.metaData != null) { pluginMetadata = ai.metaData.getBoolean(META_DATA); } } catch (NameNotFoundException e) { } IntentFilter filter = new IntentFilter("com.samsung.cordova.richnotification.remote_input_receiver"); if (richRemoteInputReceiver != null) { cordova.getActivity().getApplicationContext().registerReceiver(richRemoteInputReceiver, filter); } }
From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java
private static String buildDescription(Context context) { final PackageManager pm = context.getPackageManager(); final StringBuilder builder = new StringBuilder(); builder.append("Time : ").append(System.currentTimeMillis()).append('\n'); 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("ABIs : ").append(TextUtils.join(", ", getSupportedAbis())).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 {/* www . j a va 2 s.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:eu.faircode.netguard.LogAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values long time = cursor.getLong(colTime); int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); //String flags = cursor.getString(colFlags); String saddr = cursor.getString(colSAddr); int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); String daddr = cursor.getString(colDaddr); int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); String data = cursor.getString(colData); int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); // Get views/*from ww w . jav a 2 s . c o m*/ TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); //TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr); TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort); final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr); TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort); ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon); TextView tvUid = (TextView) view.findViewById(R.id.tvUid); TextView tvData = (TextView) view.findViewById(R.id.tvData); //ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); //ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive); // Set values tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); /*if (connection <= 0) ivConnection.setImageDrawable(null); else { if (allowed > 0) ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); else ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); } }*/ /*if (interactive <= 0) ivInteractive.setImageDrawable(null); else { ivInteractive.setImageResource(R.drawable.screen_on); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } }*/ tvProtocol.setText(Util.getProtocolName(protocol, version, false)); //tvFlags.setText(flags); if (protocol == 6 || protocol == 17) { tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); } else { tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); } // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); String[] pkg = pm.getPackagesForUid(uid); if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); } catch (PackageManager.NameNotFoundException ignored) { } if (info == null || info.icon == 0) Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon); else { Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon); Picasso.with(context).load(uri).into(ivIcon); } // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h uid = uid % 100000; // strip off user ID if (uid == -1) tvUid.setText(""); else if (uid == 0) tvUid.setText(context.getString(R.string.title_root)); else if (uid == 9999) tvUid.setText("-"); // nobody else tvUid.setText(Integer.toString(uid)); // TODO resolve source when inbound tvSAddr.setText(getKnownAddress(saddr)); if (resolve && !isKnownAddress(daddr)) if (dname == null) { tvDaddr.setText(daddr); new AsyncTask<String, Object, String>() { @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String name) { tvDaddr.setText(name); } }.execute(daddr); } else tvDaddr.setText(dname); else tvDaddr.setText(getKnownAddress(daddr)); if (TextUtils.isEmpty(data)) { tvData.setText(""); tvData.setVisibility(View.GONE); } else { tvData.setText(data); tvData.setVisibility(View.VISIBLE); } }