List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DEFAULT
int COMPONENT_ENABLED_STATE_DEFAULT
To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DEFAULT.
Click Source Link
From source file:library.artaris.cn.library.utils.SystemUtils.java
/** * ???//from w w w .j av a2 s . c o m * @param context * @return */ public static List<ResolveInfo> getShareTargets(Context context) { Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); PackageManager pm = context.getPackageManager(); return pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); }
From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java
public void setTileEnabled(ComponentName component, boolean enabled) { PackageManager pm = getPackageManager(); int state = pm.getComponentEnabledSetting(component); boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { if (enabled) { sTileBlacklist.remove(component); } else {/*from ww w. j ava2s . c o m*/ sTileBlacklist.add(component); } pm.setComponentEnabledSetting(component, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); new CategoriesUpdater().execute(); } }
From source file:com.lee.sdk.utils.Utils.java
/** * component??/*w ww .j a va2 s. com*/ * * @param ctx context * @param className class name * @return ?? */ public static boolean isComponentEnable(Context ctx, String className) { PackageManager pm = ctx.getPackageManager(); ComponentName cn = new ComponentName(ctx.getPackageName(), className); int ret = pm.getComponentEnabledSetting(cn); if (ret == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || ret == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { return true; } return false; }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
private static void application_activityStatusSwitch(Context context, Class appClass, int status) { ComponentName component = new ComponentName(appClass.getPackage().getName(), appClass.getName()); if (status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED && (context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) { context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } else if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED && (context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED || context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) { context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }// w w w.j av a2s .co m }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
private static void application_activityAliasStatusSwitch(Context context, Class appClass, String appLaunchAlias, int status) { ComponentName component = new ComponentName(appClass.getPackage().getName(), appClass.getPackage().getName() + "." + appLaunchAlias); if (status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED && (context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) { context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } else if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED && (context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED || context.getPackageManager() .getComponentEnabledSetting(component) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)) { context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }//from w w w . j av a 2s .c o m }
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
protected void resetPreferredLauncherAndOpenChooser() { PackageManager packageManager = getPackageManager(); ComponentName componentName = new ComponentName(this, HomeLauncherActivity.class); packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // Intent selector = new Intent(Intent.ACTION_MAIN); // selector.addCategory(Intent.CATEGORY_HOME); // selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // startActivity(selector); // Intent fakeIntent = new Intent(); // fakeIntent.setAction(Intent.ACTION_MAIN); // fakeIntent.addCategory(Intent.CATEGORY_HOME); // fakeIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS // | Intent.FLAG_ACTIVITY_FORWARD_RESULT // | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP // | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); // startActivity(fakeIntent); packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP); }
From source file:com.android.settings.applications.CanBeOnSdCardChecker.java
@Override public void onClick(DialogInterface dialog, int which) { if (mResetDialog == dialog) { final PackageManager pm = getActivity().getPackageManager(); final IPackageManager mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); final INotificationManager nm = INotificationManager.Stub .asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE)); final NetworkPolicyManager npm = NetworkPolicyManager.from(getActivity()); final AppOpsManager aom = (AppOpsManager) getActivity().getSystemService(Context.APP_OPS_SERVICE); final Handler handler = new Handler(getActivity().getMainLooper()); (new AsyncTask<Void, Void, Void>() { @Override// ww w . j a va 2 s. c o m protected Void doInBackground(Void... params) { List<ApplicationInfo> apps = pm .getInstalledApplications(PackageManager.GET_DISABLED_COMPONENTS); for (int i = 0; i < apps.size(); i++) { ApplicationInfo app = apps.get(i); try { if (DEBUG) Log.v(TAG, "Enabling notifications: " + app.packageName); nm.setNotificationsEnabledForPackage(app.packageName, app.uid, true); } catch (android.os.RemoteException ex) { } if (!app.enabled) { if (DEBUG) Log.v(TAG, "Enabling app: " + app.packageName); if (pm.getApplicationEnabledSetting( app.packageName) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { pm.setApplicationEnabledSetting(app.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP); } } } try { mIPm.resetPreferredActivities(UserHandle.myUserId()); } catch (RemoteException e) { } aom.resetAllModes(); final int[] restrictedUids = npm.getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND); final int currentUserId = ActivityManager.getCurrentUser(); for (int uid : restrictedUids) { // Only reset for current user if (UserHandle.getUserId(uid) == currentUserId) { if (DEBUG) Log.v(TAG, "Clearing data policy: " + uid); npm.setUidPolicy(uid, POLICY_NONE); } } handler.post(new Runnable() { @Override public void run() { if (DEBUG) Log.v(TAG, "Done clearing"); if (getActivity() != null && mActivityResumed) { if (DEBUG) Log.v(TAG, "Updating UI!"); for (int i = 0; i < mTabs.size(); i++) { TabInfo tab = mTabs.get(i); if (tab.mApplications != null) { tab.mApplications.pause(); } } if (mCurTab != null) { mCurTab.resume(mSortOrder); } } } }); return null; } }).execute(); } }
From source file:com.grazerss.EntryManager.java
public void maintainBootReceiverStateAndScheduler() { final ComponentName cName = new ComponentName(ctx, BootReceiver.class); final PackageManager pm = ctx.getPackageManager(); final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (pm.getComponentEnabledSetting(cName) != newComponentState) { Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled()); pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP); }// ww w. j av a 2s.com PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx); if (isAutoSyncEnabled()) { scheduler.ensureSchedulingIsEnabled(); } }
From source file:com.android.launcher3.Utilities.java
private static void changeDefaultLauncher(Context context) { PackageManager packageManager = context.getPackageManager(); ComponentName componentName = new ComponentName(context, FakeActivity.class); packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); Intent selector = new Intent(Intent.ACTION_MAIN); selector.addCategory(Intent.CATEGORY_HOME); selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(selector);/* ww w . java 2s. c om*/ packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP); }