2

So I'm making a launcher which has fixed buttons, and these buttons launch different applications. For the past week I've been trying to figure out how I can choose an intent (Select and app to launch, then launch it). And I've gotten that part right. But what I'm looking for is a way to save these intents, because I am using the same method for my other buttons, but as soon as i select "use as default" in the pop up, this gets assigned to all the buttons and all the buttons open the calculator app. I just want the user to select which app they want as default and then launch it for that button forever.

I've been searching this site, google, and many other sites for solutions but I'm out. In my other answer I was told to use a specific method, and then use shared preference to save it. But I don't get it.

I would like a simple method where the user gets to select the intent if they haven't already, then as soon as they select it, the selection gets stored so if the user goes back and tap the button again it opens the app they had chosen.

Basically a App Chooser/Picker.

Different codes I've implemented.

 @Override
 public void onClick(View v) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            if (!prefs.getBoolean("FileExplorer", false)) {

             final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
             mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
             final List pkgAppsList = getActivity().getPackageManager().queryIntentActivities( mainIntent, 0);
             startActivity(Intent.createChooser(mainIntent, "Choose your default app"));

            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("FileExplorer", true);
            editor.commit();
     }
 }
});

And

 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
 final List pkgAppsList = getActivity().getPackageManager().queryIntentActivities( mainIntent, 0);
 startActivity(Intent.createChooser(mainIntent, "Choose your default app"));

Thanks for your time, hopefully you can help out, and it'd be great if you gave an example.

Robin
  • 577
  • 1
  • 7
  • 13

0 Answers0