问题
I just want to open phone call application of android device. I dont want to provide that application a phone number. Just want to open it.
I am using phone application's package name to open it. Because I am able to open any application I want through that package name with the code below.Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.contacts");
startActivity(launchIntent);
I am not able to open Phone and Contacts application with the above code. What can be the problem?
回答1:
Intents
are intended (no pwn intended here (damn!)) to give you a more generic way of accessing actions such as opening a file. If you had to specify the package of whatever you wanted to do this would be very limited. However, here are some of the intents that may be what you're after.
//For the contacts (picking one)
Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
//For the contacts (viewing them)
Intent i = new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);
//For the dial pad
Intent i = new Intent(Intent.ACTION_DIAL, null);
//For viewing the call log
Intent i = new Intent(Intent.ACTION_VIEW, CallLog.Calls.CONTENT_URI);
Make yourself a useful intents
file somewhere to save you time in the future, you'll thank me later someday.
Of course to start those intents you'd do startActivity(i);
for all excepting the first one, since you'd want the contact back and you'd need startActivityForResult(i);
but that's another story.
回答2:
public static final String ACTION_DIAL
Since: API Level 1 Activity Action: Dial a number as specified by the data. This shows a UI with the number being dialed, allowing the user to explicitly initiate the call. Input: If nothing, an empty dialer is started;
Source: http://developer.android.com/reference/android/content/Intent.html#ACTION_DIAL
http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL could be also what you are looking for.
If you want to start the phone call from an Activity, just use http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent) from the Activity's Context.
来源:https://stackoverflow.com/questions/10732641/android-open-phone-call-application