0

What I want to archive is that when user click number which appears to be phone number, USSD code or has the ability to be used by dialer, the phone should list apps for the user to choose which application to use when making the call and let user choose which app to be default for in future.

AM just beginner to android I tried searching but I can't find any related question and I don't know where to start.

The other question is the operation result on onNewIntent or onActivityResult

Thanks.

Paul Chu
  • 1,249
  • 3
  • 19
  • 27
JoDee
  • 59
  • 1
  • 9

1 Answers1

0

You want to use implicit intent:

// build intent
Uri number = Uri.parse("tel:5551234"); // replace 5551234 with your number
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);

// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(callIntent, 0);
boolean isIntentSafe = activities.size() > 0;

// Start an activity if it's safe
if (isIntentSafe) {
    startActivity(callIntent);
}
Stefan Golubović
  • 1,225
  • 1
  • 16
  • 21
  • Will this prompt user to choose app to complete action with? – JoDee Mar 11 '18 at 21:59
  • you seem to make a call not invoke complete action with – JoDee Mar 11 '18 at 22:01
  • I already wrote a function to make calls, what i want is the app to receive phone number from other apps touch – JoDee Mar 11 '18 at 22:01
  • Since this is implicit intent, it will show user list of apps that can handle that action, as you can see [here on figure 1](https://developer.android.com/training/basics/intents/sending.html#StartActivity). If you want your app to receive numbers from other apps, you need to define [intent filter](https://developer.android.com/guide/components/intents-filters.html#Receiving). – Stefan Golubović Mar 12 '18 at 08:52