You can do this (disable the intent filter from android manifest programatically) by using Activity Alias:
1) add (e.g. AliasMySocialNetworkActivity) in AndroidManifest.xml to your MySocialNetworkActivity and move your intent-filter to them. It will be looks like that:
<activity-alias
android:targetActivity=".MySocialNetworkActivity"
android:name=".AliasMySocialNetworkActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity-alias>
2) add this code to suppress intent-filter in alias activity when You need that
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName compName =
new ComponentName(getPackageName(), getPackageName() + ".AliasMySocialNetworkActivity");
pm.setComponentEnabledSetting(
compName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
3) restore intent-filter, when You need it:
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName compName =
new ComponentName(getPackageName(), getPackageName() + ".AliasMySocialNetworkActivity");
pm.setComponentEnabledSetting(
compName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
For more details see this or that answer.
Update
Actually You don't need Alias, just use PackageManager.COMPONENT_ENABLED_STATE_DISABLED
/PackageManager.COMPONENT_ENABLED_STATE_ENABLED
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName compName =
new ComponentName(getPackageName(), getPackageName() + ".MySocialNetworkActivity");
pm.setComponentEnabledSetting(
compName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
directly on your activity. Thanks @pskink.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…