There is a dirty great hack that allows you to do this. The inspiration for this hack can be found here.
Idea
is to make it an Android pattern that a new browser has just been installed, giving it a fake component with a typical browser intent filter. I will give a small test case as a proof of concept, and you decide how you can use it in your real application.
Proposed approach
It seems common and applicable in many cases (not only for launchers and browsers) and depends only on the intent filter that is supplied to the converter.
Suppose we want to override the default action to view a simple http: // link . We will declare fake browser activity next to the real ones in AndroidManifest.xml:
<activity android:name=".FakeActivity" android:enabled="false"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="http" /> </intent-filter> </activity>
FakeActivity is completely empty:
public class FakeActivity extends Activity {}
We will show the application selection by clicking the simple button found in the activity_main.xml file, and check the default behavior by clicking another button:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View changeDefaultButton = findViewById(R.id.changeDefButton); changeDefaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showChooser(); } }); View testDefaultButton = findViewById(R.id.testDefaultButton); testDefaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { runDefaultApp(); } }); } void showChooser(){ PackageManager pm = getPackageManager(); ComponentName cm = new ComponentName(this, FakeActivity.class); pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); runDefaultApp(); pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } void runDefaultApp(){ Intent selector = new Intent(Intent.ACTION_VIEW); selector.setData(Uri.parse("http://stackoverflow.com")); startActivity(selector); }
Each time you click changeDefaultButton , a selection dialog is displayed (provided that at least two suitable browser applications are installed). In addition, the selection dialog always allows the user to set the selected application by default .
References:
GitHub Evidence-Based Project
Hope this helps.
Drew
source share