Why does Intent.createChooser() need a BroadcastReceiver and how to implement?

前端 未结 2 1808
盖世英雄少女心
盖世英雄少女心 2020-12-10 13:07

The following snippet, called from my implementation of onOptionsItemSelected(), works nicely to carry the user from my app to a mail client with email address,

2条回答
  •  既然无缘
    2020-12-10 13:23

    Simple resolution of problem.

    More info here: https://developer.android.com/training/basics/intents/sending.html

    Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
    
    PackageManager pkManager = getPackageManager();
    List activities = pkManager.queryIntentActivities(mapIntent, 0);
    
    if (activities.size() > 1) {
        // Create and start the chooser
        Intent chooser = Intent.createChooser(mapIntent, "Open with");
        startActivity(chooser);
    
      } else {
        startActivity( mapIntent );
    }
    

提交回复
热议问题