Create Intent by chooser and check safe before start a Activity

    
     //
Build the intent //Uri number = Uri.parse("tel:5551234"); //Intent callIntent = new Intent(Intent.ACTION_DIAL, number); Intent intent = new Intent(Intent.ACTION_SEND); // Always use string resources for UI text. This says something like "Share this photo with" EditText edittext=(EditText)findViewById(R.id.edit_message); String title =edittext.getText().toString(); // Create and start the chooser Intent chooser = Intent.createChooser(intent, title); startActivity(chooser); // Verify it resolves PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(chooser, 0); boolean isIntentSafe = activities.size() > 0; // Start an activity if it's safe if (isIntentSafe) { startActivity(chooser); }
原文地址:https://www.cnblogs.com/nikyxxx/p/2684009.html