Request default activity without actually opening an operation

I need to set the default application for a specific mime type. I know how to clear by default, but I need to then request the user without actually opening the application.

PackageManager p = mContext.getPackageManager();
ComponentName cN = new ComponentName(mContext, FakeDownloadActivity.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Intent selector = new Intent(Intent.ACTION_DEFAULT);
selector.addCategory(Intent.CATEGORY_DEFAULT);
selector.setType(mimeType);
mContext.startActivity(selector);

p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

In the above code, the action is triggered, not ONLY to select the default activity. It works by allowing fake activity and then turning it off. This causes the Select Default Application dialog box to appear on the next call. I just want to ONLY select the default activity.

+4
source share
1 answer

What you are looking for is intention ACTION_PICK_ACTIVITY.

, , , :

Intent mainIntent = new Intent(Intent.ACTION_DEFAULT, null);
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);

ACTION_PICK_ACTIVITY, - ,

Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);

:

startActivityForResult(pickIntent, 0);

, , , , onActivityResult . :

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

               //In data, you have all the information about the selected application
       if (data != null) {
                 //You can launch the application that we just picked with startActivity(data);
                 //or explore the variable to get all the information than you want
       }
    }

Intent. , .

- , . , , , , , - . , , - . , addPreferredActivity, , API 8, :

API, . . . , Context.startActivity() , .

+6

All Articles