Android open phone call application

懵懂的女人 提交于 2019-12-21 19:51:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!