Search in sources :

Example 61 with PackageManager

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);
    }
}
Also used : ContentValues(android.content.ContentValues) ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 62 with PackageManager

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);
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView)

Example 63 with PackageManager

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;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 64 with PackageManager

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);
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable)

Example 65 with PackageManager

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

PackageManager (android.content.pm.PackageManager)1482 Intent (android.content.Intent)505 ResolveInfo (android.content.pm.ResolveInfo)460 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)353 PackageInfo (android.content.pm.PackageInfo)270 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)127 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)91 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)55 ServiceInfo (android.content.pm.ServiceInfo)48