本文整理汇总了Java中android.content.pm.PackageManager.getComponentEnabledSetting方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getComponentEnabledSetting方法的具体用法?Java PackageManager.getComponentEnabledSetting怎么用?Java PackageManager.getComponentEnabledSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getComponentEnabledSetting方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
if (intent == null) {
return;
}
final String packageName = intent.getStringExtra("PackageName");
PackageManager pm = context.getApplicationContext().getPackageManager();
if (PackageManager.COMPONENT_ENABLED_STATE_ENABLED == pm.getComponentEnabledSetting(new ComponentName(context,
RedirectHandlerActivity.class))
&& !context.getPackageName().equals(packageName)) {
Log.d(TAG, "Disabling RedirectHandlerActivity for this application: " + context.getPackageName());
pm.setComponentEnabledSetting(new ComponentName(context, RedirectHandlerActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
final Intent returnIntent = new Intent();
returnIntent.setAction(REDIRECT_PROBLEM_INTENT);
returnIntent.putExtra(REDIRECT_RETURN_URI_KEY, intent.getData());
LocalBroadcastManager.getInstance(context).sendBroadcast(returnIntent);
}
}
示例2: applyComponentEnablingState
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void applyComponentEnablingState(boolean active) {
int enableState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
if(active && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.INTEGRATE_TEL_PRIVILEGED) ) {
// Check whether we should register for stock tel: intents
// Useful for devices without gsm
enableState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}
PackageManager pm = getPackageManager();
ComponentName cmp = new ComponentName(this, "com.csipsimple.ui.PrivilegedOutgoingCallBroadcaster");
try {
if (pm.getComponentEnabledSetting(cmp) != enableState) {
pm.setComponentEnabledSetting(cmp, enableState, PackageManager.DONT_KILL_APP);
}
} catch (IllegalArgumentException e) {
Log.d(THIS_FILE,
"Current manifest has no PrivilegedOutgoingCallBroadcaster -- you can ignore this if voluntary", e);
}
}
示例3: disableComponent
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void disableComponent() {
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
// packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
// PackageManager.DONT_KILL_APP);
int res = packageManager.getComponentEnabledSetting(componentName);
if (res == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|| res == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
// 隐藏应用图标
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
} else {
// 显示应用图标
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
PackageManager.DONT_KILL_APP);
}
}
示例4: setServicesEnabled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static void setServicesEnabled(Context context, boolean enabled, Integer wakeLockId) {
PackageManager pm = context.getPackageManager();
if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
/*
* If no accounts now exist but the service is still enabled we're about to disable it
* so we'll reschedule to kill off any existing alarms.
*/
MailService.actionReset(context, wakeLockId);
}
Class<?>[] classes = { MessageCompose.class, BootReceiver.class, MailService.class };
for (Class<?> clazz : classes) {
boolean alreadyEnabled = pm.getComponentEnabledSetting(new ComponentName(context, clazz)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
if (enabled != alreadyEnabled) {
pm.setComponentEnabledSetting(
new ComponentName(context, clazz),
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
}
if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
/*
* And now if accounts do exist then we've just enabled the service and we want to
* schedule alarms for the new accounts.
*/
MailService.actionReset(context, wakeLockId);
}
}
示例5: isComponentEnabled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static boolean isComponentEnabled(PackageManager manager, ComponentName component) {
switch (manager.getComponentEnabledSetting(component)) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return false;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
default:
try {
PackageInfo packageInfo = manager.getPackageInfo(
component.getPackageName(),
PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
| PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
List<ComponentInfo> components = new ArrayList<>();
if (packageInfo.activities != null) {
Collections.addAll(components, packageInfo.activities);
}
if (packageInfo.services != null) {
Collections.addAll(components, packageInfo.services);
}
if (packageInfo.providers != null) {
Collections.addAll(components, packageInfo.providers);
}
for (ComponentInfo componentInfo : components) {
if (componentInfo.name.equals(component.getClassName())) {
return componentInfo.isEnabled();
}
}
return false;
} catch (PackageManager.NameNotFoundException e) {
// the package isn't installed on the device
return false;
}
}
}
示例6: setComponentState
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static void setComponentState(PackageManager pm, ComponentName componentName, boolean enable) {
final int oldState = pm.getComponentEnabledSetting(componentName);
final int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
if (newState != oldState) {
final int flags = PackageManager.DONT_KILL_APP;
pm.setComponentEnabledSetting(componentName, newState, flags);
}
}
示例7: isComponentEnabled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean isComponentEnabled(PackageManager pm, String pkg, String cls) {
ComponentName componentName = new ComponentName(pkg, cls);
int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);
switch (componentEnabledSetting) {
case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
return false;
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
return true;
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
default:
// We need to get the application info to get the component's default state
try {
PackageInfo packageInfo = pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES
| PackageManager.GET_RECEIVERS
| PackageManager.GET_SERVICES
| PackageManager.GET_PROVIDERS
| PackageManager.GET_DISABLED_COMPONENTS);
List<ComponentInfo> components = new ArrayList<>();
if (packageInfo.activities != null) Collections.addAll(components, packageInfo.activities);
if (packageInfo.services != null) Collections.addAll(components, packageInfo.services);
if (packageInfo.providers != null) Collections.addAll(components, packageInfo.providers);
for (ComponentInfo componentInfo : components) {
if (componentInfo.name.equals(cls)) {
return componentInfo.enabled; //This is the default value (set in AndroidManifest.xml)
//return componentInfo.isEnabled(); //Whole package dependant
}
}
// the component is not declared in the AndroidManifest
return false;
} catch (PackageManager.NameNotFoundException e) {
// the package isn't installed on the device
return false;
}
}
}
示例8: customReceiverPass
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Check package's MiPush custom receiver (handle com.xiaomi.mipush.RECEIVE_MESSAGE action)
* is enabled.
* @see PushMessageReceiver
* @see Constants#ACTION_RECEIVE_MESSAGE
* @param info Package info
* @return enable status. If this package not have custom receiver, will
* still returns true.
*/
private boolean customReceiverPass (PackageInfo info, PackageManager packageManager) {
//if (info.receivers == null)
// return true;
Intent intent = new Intent();
intent.setPackage(info.packageName);
//intent.setAction(Constants.ACTION_RECEIVE_MESSAGE);
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent,
PackageManager.GET_RESOLVED_FILTER |
PackageManager.GET_DISABLED_COMPONENTS)) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (!activityInfo.packageName.equals(info.packageName))
continue;
IntentFilter filter = resolveInfo.filter;
if (filter != null && filter.hasAction(Constants.ACTION_RECEIVE_MESSAGE)) {
boolean enabled = packageManager.getComponentEnabledSetting(new ComponentName(
activityInfo.packageName, activityInfo.name
)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Log4a.i(TAG, "Handle receiver: " + activityInfo.name +
"; enabled: " + enabled);
return enabled;
}
}
Log4a.d(TAG, "Not found custom message receiver in " + info.packageName);
// Not found
return true;
}
示例9: enableNotificationListener
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static void enableNotificationListener(Context paramContext, ComponentName paramComponentName, boolean paramBoolean){
if (Build.VERSION.SDK_INT >= 18)
{
if (checkWriteSecureSettingPermission(paramContext))
{
if (paramBoolean)
{
PackageManager packageManager = paramContext.getPackageManager();
if (packageManager.getComponentEnabledSetting(paramComponentName) != 1) {
packageManager.setComponentEnabledSetting(paramComponentName, 1, 1);
}
}
ContentResolver contentResolver = paramContext.getContentResolver();
List localObject = getEnabledNotificationListeners(contentResolver);
if (paramBoolean) {
if (!(localObject).contains(paramComponentName))
{
(localObject).add(paramComponentName);
addNotificationListeners(contentResolver, localObject);
}
}else {
localObject.remove(localObject);
addNotificationListeners(contentResolver, localObject);
}
return;
}
throw new SecurityException("android.permission.WRITE_SECURE_SETTINGS not be granted on this devices(SDK=)" + Build.VERSION.SDK_INT);
}
throw new UnsupportedOperationException("ENABLED_NOTIFICATION_LISTENERS not be supported on this devices(SDK=)" + Build.VERSION.SDK_INT);
}
示例10: wasComponentEnabled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Checks if component for provided class enabled before.
*
* @param context Current Context.
* @param packageManager Current PackageManager.
* @param clazz Class for check.
* @return True if component was enabled before.
*/
public static boolean wasComponentEnabled(Context context, PackageManager packageManager,
Class clazz) {
if (clazz == null || context == null || packageManager == null) {
return false;
}
int componentStatus = packageManager.getComponentEnabledSetting(new ComponentName(context,
clazz));
if (PackageManager.COMPONENT_ENABLED_STATE_DEFAULT == componentStatus ||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED == componentStatus) {
return false;
}
return true;
}
示例11: onHideAppIconClicked
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@OnClick(R.id.btn_hide_app_icon)
public void onHideAppIconClicked() {
PackageManager manager = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
int status = manager.getComponentEnabledSetting(componentName);
if (status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT ||
status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} else {
manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
}
}
示例12: isComponentDefault
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* get the component in our package default
* @param context
* @param componentClassName
*/
public static boolean isComponentDefault(Context context, String componentClassName){
PackageManager pm = context.getPackageManager();
ComponentName componentName = new ComponentName(context.getPackageName(), componentClassName);
return pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}