当前位置: 代码迷 >> Android >> DevicePolicyManager 的 addPersistentPreferredActivity() 方法不起作用
  详细解决方案

DevicePolicyManager 的 addPersistentPreferredActivity() 方法不起作用

热度:89   发布时间:2023-08-04 11:41:25.0

我正在使用 DevicePolicyManager 的 addPersistentPreferredActivity() 方法,但它不起作用。

我使用 dpm 命令将 Google Nexus 5.0 android 设备设为设备所有者,之后我使用上述方法将我的应用程序的活动设为 HomeActivity,但它不起作用。

下面是我正在使用的一段代码:

IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
filter.addCategory(Intent.CATEGORY_DEFAULT);
devicePolicyManager.addPersistentPreferredActivity(demoDeviceAdmin,filter,new ComponentName(getApplicationContext(),LauncherActivity.class));

谁能帮我解决这个问题?

也许你忘了在你的活动清单中添加这个:

<intent-filter>
     <category android:name="android.intent.category.HOME" />
     <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  相关解决方案