Search in sources :

Example 26 with PackageManager

use of android.content.pm.PackageManager in project Libraries-for-Android-Developers by eoecn.

the class ActionMenu method addIntentOptions.

public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;
    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(groupId);
    }
    for (int i = 0; i < N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
        final MenuItem item = add(groupId, itemId, order, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }
    return N;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) MenuItem(com.actionbarsherlock.view.MenuItem)

Example 27 with PackageManager

use of android.content.pm.PackageManager in project Libraries-for-Android-Developers by eoecn.

the class MenuBuilder method addIntentOptions.

public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;
    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(group);
    }
    for (int i = 0; i < N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
        final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }
    return N;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) MenuItem(com.actionbarsherlock.view.MenuItem)

Example 28 with PackageManager

use of android.content.pm.PackageManager in project Libraries-for-Android-Developers by eoecn.

the class ActivityChooserView method updateAppearance.

/**
     * Updates the buttons state.
     */
private void updateAppearance() {
    // Expand overflow button.
    if (mAdapter.getCount() > 0) {
        mExpandActivityOverflowButton.setEnabled(true);
    } else {
        mExpandActivityOverflowButton.setEnabled(false);
    }
    // Default activity button.
    final int activityCount = mAdapter.getActivityCount();
    final int historySize = mAdapter.getHistorySize();
    if (activityCount > 0 && historySize > 0) {
        mDefaultActivityButton.setVisibility(VISIBLE);
        ResolveInfo activity = mAdapter.getDefaultActivity();
        PackageManager packageManager = mContext.getPackageManager();
        mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
        if (mDefaultActionButtonContentDescription != 0) {
            CharSequence label = activity.loadLabel(packageManager);
            String contentDescription = mContext.getString(mDefaultActionButtonContentDescription, label);
            mDefaultActivityButton.setContentDescription(contentDescription);
        }
        // Work-around for #415.
        mAdapter.setShowDefaultActivity(false, false);
    } else {
        mDefaultActivityButton.setVisibility(View.GONE);
    }
    // Activity chooser content.
    if (mDefaultActivityButton.getVisibility() == VISIBLE) {
        mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
    } else {
        mActivityChooserContent.setBackgroundDrawable(null);
        mActivityChooserContent.setPadding(0, 0, 0, 0);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager)

Example 29 with PackageManager

use of android.content.pm.PackageManager in project android-job by evernote.

the class GcmAvailableHelper method setServiceEnabled.

private static void setServiceEnabled(Context context, boolean enabled) {
    try {
        PackageManager packageManager = context.getPackageManager();
        // use a string, the class object probably cannot be instantiated
        String className = JobProxyGcm.class.getPackage().getName() + ".PlatformGcmService";
        ComponentName component = new ComponentName(context, className);
        int componentEnabled = packageManager.getComponentEnabledSetting(component);
        switch(componentEnabled) {
            case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                if (!enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                    Cat.i("GCM service disabled");
                }
                break;
            // default is disable
            case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                if (enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    Cat.i("GCM service enabled");
                }
                break;
        }
    } catch (Throwable t) {
        // just in case, don't let the app crash with each restart
        Cat.e(t);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 30 with PackageManager

use of android.content.pm.PackageManager in project android_frameworks_base by ParanoidAndroid.

the class ApplicationErrorReport method getErrorReportReceiver.

public static ComponentName getErrorReportReceiver(Context context, String packageName, int appFlags) {
    // check if error reporting is enabled in secure settings
    int enabled = Settings.Global.getInt(context.getContentResolver(), Settings.Global.SEND_ACTION_APP_ERROR, 0);
    if (enabled == 0) {
        return null;
    }
    PackageManager pm = context.getPackageManager();
    // look for receiver in the installer package
    String candidate = pm.getInstallerPackageName(packageName);
    ComponentName result = getErrorReportReceiver(pm, packageName, candidate);
    if (result != null) {
        return result;
    }
    // error receiver
    if ((appFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        candidate = SystemProperties.get(SYSTEM_APPS_ERROR_RECEIVER_PROPERTY);
        result = getErrorReportReceiver(pm, packageName, candidate);
        if (result != null) {
            return result;
        }
    }
    // if there is a default receiver, try that
    candidate = SystemProperties.get(DEFAULT_ERROR_RECEIVER_PROPERTY);
    return getErrorReportReceiver(pm, packageName, candidate);
}
Also used : PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Aggregations

PackageManager (android.content.pm.PackageManager)1429 Intent (android.content.Intent)483 ResolveInfo (android.content.pm.ResolveInfo)449 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)345 ApplicationInfo (android.content.pm.ApplicationInfo)249 PackageInfo (android.content.pm.PackageInfo)248 ComponentName (android.content.ComponentName)239 ArrayList (java.util.ArrayList)156 ActivityInfo (android.content.pm.ActivityInfo)135 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 IPackageManager (android.content.pm.IPackageManager)93 Drawable (android.graphics.drawable.Drawable)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)71 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)63 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)46