Java Code Examples for android.content.pm.PackageManager.setComponentEnabledSetting()

The following are Jave code examples for showing how to use setComponentEnabledSetting() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: okwallet   File: RequestCoinsFragment.java   View Source Code Vote up 6 votes
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();
}
 
Example 2
Project: PretendSharing   File: SettingsActivity.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: robird-reborn   File: NavigationUtils.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 4
Project: StopApp   File: SettingActivity.java   View Source Code Vote up 6 votes
/**
     * 切换桌面图标
     *
     * @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);
//            }
//        }
    }
 
Example 5
Project: Leanplum-Android-SDK   File: LeanplumManifestHelper.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 6
Project: UnforgetIt   File: AlarmReceiver.java   View Source Code Vote up 5 votes
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);

    }
}
 
Example 7
Project: CustomAndroidOneSheeld   File: NfcShield.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 8
Project: Zebpay-Unblock   File: ZebpayUnblockActivity.java   View Source Code Vote up 5 votes
@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();
}
 
Example 9
Project: CustomAndroidOneSheeld   File: MainActivity.java   View Source Code Vote up 5 votes
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();
        }
    }
}
 
Example 10
Project: Bridge   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 11
Project: FlickLauncher   File: Utilities.java   View Source Code Vote up 5 votes
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);
}
 
Example 12
Project: ePills   File: ClockActivity.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 13
Project: KernelAdiutor-Mod   File: Utils.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 14
Project: Dendroid-HTTP-RAT   File: Drodian.java   View Source Code Vote up 5 votes
@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");
	}
}
 
Example 15
Project: FinalProject   File: DiscoverActivity.java   View Source Code Vote up 5 votes
public static void makePrefered(Context c) {
    PackageManager p = c.getPackageManager();
    ComponentName cN = new ComponentName(c, DiscoverActivity.class);
    p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    Intent selector = new Intent(Intent.ACTION_MAIN);
    selector.addCategory(Intent.CATEGORY_HOME);
    c.startActivity(selector);
    p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
 
Example 16
Project: REDAndroid   File: AndroidComponentUtil.java   View Source Code Vote up 5 votes
public static void toggleComponent(Context context, Class componentClass, boolean enable) {
    ComponentName componentName = new ComponentName(context, componentClass);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(componentName,
            enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}
 
Example 17
Project: MTweaks-KernelAdiutorMOD   File: Utils.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 18
Project: Say_it   File: NotificationReceiver.java   View Source Code Vote up 4 votes
public static void scheduleNotification(Context context, int hour, int minute, String mode) {

        //this is the method to schedule the notification. It uses an alarmManager built in Android to set, with the Calendar Class, an event in a specific time set by the user
        int mode_code = Integer.parseInt(mode);
        ComponentName receiver = new ComponentName(context, NotificationBootReceiver.class);
        PackageManager pm = context.getPackageManager();

        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, NotificationReceiver.class);
        PendingIntent notificationPendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        if (mode_code == 0) {
            //Notification OFF
            alarmManager.cancel(notificationPendingIntent);
            pm.setComponentEnabledSetting(receiver,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            return;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());

        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, 0);


        if (mode_code == 2) {
            //Daily Notifications. IF statement is important in order to set the notification the day after, if the current time is equal or bigger to the set one.
            if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
                calendar.setTimeInMillis(calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY);
            }

                alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, notificationPendingIntent);
        } else if (mode_code == 1) {
            //Weekly Notifications
            if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
                calendar.setTimeInMillis(calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY * 7);
            }

            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, notificationPendingIntent);
        }

        pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }
 
Example 19
Project: DoNotDisturbSync   File: MainActivity.java   View Source Code Vote up 4 votes
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);
}
 
Example 20
Project: DoNotDisturbSync   File: MainActivity.java   View Source Code Vote up 4 votes
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);
}