4

I'm trying to add persisted activity to intent filter, I am profile owner and device owner and this is verified and I have no security exception but still my activity is not interrupting the call, not sure what to do next ...help please

ComponentName adminComponent = new ComponentName(getApplicationContext(), EnforcerDeviceAdminReceiver.class);
ComponentName handlerComponent = new ComponentName(getApplicationContext(), HandlerActivity.class);

devicePolicyManager.clearPackagePersistentPreferredActivities(adminComponent, getPackageName());

IntentFilter intentFilter = new IntentFilter(INTENT_ACTION);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);

devicePolicyManager.addPersistentPreferredActivity(adminComponent, intentFilter, handlerComponent);

After adding this I am launching startActivity(new Intent(INTENT_ACTION)); from another application but this is not interrupted by the above activity.

Stefan Hoffmann
  • 3,214
  • 16
  • 30
ali mohsin
  • 41
  • 2
  • I'm currently facing the same problem on Android 7.0. If I check the default apps in the settings UI, I can even see that my specified app is assigned as default app (HOME intent in this case) after calling `addPersistentPreferredActivity`, but the old previously assigned app is still reacting to the intent. Maybe even worse, the user can still change the assigned activity, so it is not really persistent. – Stefan Hoffmann Dec 04 '17 at 18:14

2 Answers2

0

I've tried several things without being able to make it works.

However, the source code seems to do what the documentation say, so I guess the feature is currently broken (Android 5.0).

Hartok
  • 2,147
  • 20
  • 37
0

I have met the same issue, fix by follow:

Please make sure you have set the intent filter

<intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.HOME" />
</intent-filter>

to the component in your manifest.

Because the addPersistentPreferredActivity() just tell the system when there is an implicit intent, use my component to handle it rather than other component.

So you need to add intent filters to your component to make sure it can receive the intent.