use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class DatabaseHelper method loadBookmarks.
/**
* Loads the default set of bookmarked shortcuts from an xml file.
*
* @param db The database to write the values into
*/
private void loadBookmarks(SQLiteDatabase db) {
ContentValues values = new ContentValues();
PackageManager packageManager = mContext.getPackageManager();
try {
XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
XmlUtils.beginDocument(parser, "bookmarks");
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (!"bookmark".equals(name)) {
break;
}
String pkg = parser.getAttributeValue(null, "package");
String cls = parser.getAttributeValue(null, "class");
String shortcutStr = parser.getAttributeValue(null, "shortcut");
String category = parser.getAttributeValue(null, "category");
int shortcutValue = shortcutStr.charAt(0);
if (TextUtils.isEmpty(shortcutStr)) {
Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
continue;
}
final Intent intent;
final String title;
if (pkg != null && cls != null) {
ActivityInfo info = null;
ComponentName cn = new ComponentName(pkg, cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e) {
String[] packages = packageManager.canonicalToCurrentPackageNames(new String[] { pkg });
cn = new ComponentName(packages[0], cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e1) {
Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
continue;
}
}
intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(cn);
title = info.loadLabel(packageManager).toString();
} else if (category != null) {
intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
title = "";
} else {
Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr + ": missing package/class or category attributes");
continue;
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
values.put(Settings.Bookmarks.TITLE, title);
values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
db.delete("bookmarks", "shortcut = ?", new String[] { Integer.toString(shortcutValue) });
db.insert("bookmarks", null, values);
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
} catch (IOException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
}
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class TaskCardView method setThumbnailView.
private void setThumbnailView() {
ImageView screenshotView = (ImageView) findViewById(R.id.card_view_banner_icon);
PackageManager pm = getContext().getPackageManager();
if (mTask.thumbnail != null) {
setAsScreenShotView(mTask.thumbnail, screenshotView);
} else {
try {
Drawable banner = null;
if (mTask.key != null) {
banner = pm.getActivityBanner(mTask.key.baseIntent);
}
if (banner != null) {
setAsBannerView(banner, screenshotView);
} else {
setAsIconView(mTask.icon, screenshotView);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Package not found : " + e);
setAsIconView(mTask.icon, screenshotView);
}
}
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class CastControllerImpl method getAppName.
private String getAppName(String packageName) {
final PackageManager pm = mContext.getPackageManager();
try {
final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
if (appInfo != null) {
final CharSequence label = appInfo.loadLabel(pm);
if (!TextUtils.isEmpty(label)) {
return label.toString();
}
}
Log.w(TAG, "No label found for package: " + packageName);
} catch (NameNotFoundException e) {
Log.w(TAG, "Error getting appName for package: " + packageName, e);
}
return packageName;
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class AppWidgetServiceImpl method createMaskedWidgetBitmap.
private Bitmap createMaskedWidgetBitmap(String providerPackage, int providerUserId) {
final long identity = Binder.clearCallingIdentity();
try {
// Load the unbadged application icon and pass it to the widget to appear on
// the masked view.
Context userContext = mContext.createPackageContextAsUser(providerPackage, 0, UserHandle.of(providerUserId));
PackageManager pm = userContext.getPackageManager();
Drawable icon = pm.getApplicationInfo(providerPackage, 0).loadUnbadgedIcon(pm);
// Create a bitmap of the icon which is what the widget's remoteview requires.
return mIconUtilities.createIconBitmap(icon);
} catch (NameNotFoundException e) {
Slog.e(TAG, "Fail to get application icon", e);
// purged very soon.
return null;
} finally {
Binder.restoreCallingIdentity(identity);
}
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class ConnectionUtil method downloadManagerUid.
/**
* Fetch the Download Manager's UID.
* @return the Download Manager's UID
*/
public int downloadManagerUid() {
try {
PackageManager pm = mContext.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo(DOWNLOAD_MANAGER_PKG_NAME, PackageManager.GET_META_DATA);
return appInfo.uid;
} catch (NameNotFoundException e) {
Log.d(LOG_TAG, "Did not find the package for the download service.");
return -1;
}
}
Aggregations