如何显示在Android上使用一个单一的意图都发短信和拨号器应用程序? [英] How to show both texting and dialer apps with a single Intent on Android?
问题描述
这是我的应用程序,用户可以发短信/呼叫的人。我开始通过意向的活动在我的应用程序,目前1短信和1拨号程序,是有可能结合这些,例如因此,当用户点击一个按钮来调用/文本它带来了短信/拨号器应用程序的清单1中的窗口?
From my app, the user can text/call a person. I am starting an Activity through Intent in my app, currently 1 for texting and 1 for the dialer, is it possible to combine these, e.g. so when user clicks a button to call/text it brings up a list of texting/dialer apps in 1 window ?
拨号:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + somenumber));
startActivity(callIntent);
信息的应用程序:
Messaging app:
Intent callIntent = new Intent(Intent.ACTION_PROCESS_TEXT);
callIntent.setData(Uri.parse("tel:" + somenumber));
startActivity(callIntent);
我想要做的是,而不必为通话说明文字两个单独的按钮1和1,我希望能有1和点击时,就应该让用户无论是打电话或发短信。
What I want to do is, instead of having two separate buttons 1 for text and 1 for call, I want to have 1 and when clicked, it should allow users to either call or text.
推荐答案
您可以通过实现这个 Intent.EXTRA_INITIAL_INTENTS
伴有queryIntentActivities。
You can achieve this using Intent.EXTRA_INITIAL_INTENTS
accompanied by queryIntentActivities.
有点复杂,但它的工作尝试低于code ..
Little complex but it will work try the below code..
final List<Intent> finalIntents = new ArrayList<Intent>();
final Intent textIntent = new Intent(Intent.ACTION_VIEW);
textIntent.setType("text/plain");
textIntent.setData(Uri.parse("sms:"));
final PackageManager packageManager = getActivity().getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(textIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(textIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
finalIntents.add(intent);
}
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:121"));
Intent chooserIntent = Intent.createChooser(
callIntent, "Select app to share");
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS, finalIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
祝您好运..!
这篇关于如何显示在Android上使用一个单一的意图都发短信和拨号器应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!