I have a feature that I only want to be available only when certain conditions are met so I have this activity alias:
<activity-alias android:name="share-files-text"
android:targetActivity=".MyActivity"
android:exported="true"
android:enabled="false">
<intent-filter android:label="@string/open_with">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/pdf" />
<data android:mimeType="image/*" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity-alias>
Once in activity I have this code to enable the component
String packageName = getPackageName();
ComponentName componentWithTextFiles = new ComponentName(packageName, "share-files-text");
ComponentName componentWithoutTextFiles = new ComponentName(packageName, "share-files");
if(DebugAndTestSettings.ENABLE_TEXT_SLIDE){
getPackageManager().setComponentEnabledSetting(componentWithTextFiles, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
getPackageManager().setComponentEnabledSetting(componentWithoutTextFiles, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
} else {
getPackageManager().setComponentEnabledSetting(componentWithTextFiles, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
getPackageManager().setComponentEnabledSetting(componentWithoutTextFiles, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
}
The problem is it crashes saying the package blabla doesn't contain an activity named share-files-text, how can disable/enable this element suing the alias name? Thanks
EDIT: I got the idea from this post: Android: Can I enable/disable an activity's intent filter programmatically?