如何在主屏幕上打开diler应用程序,显示最近和搜索(不是拨号盘)。
我已尝试context.getPackageManager().getLaunchIntentForPackage("com.android.diler")
但它返回null com.android.diler
也返回null。
答案 0 :(得分:1)
这个怎么样:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
编辑:提供启动拨号程序的代码,就像在HOME屏幕上一样
阿。问题是不只有一个拨号器。每个电话制造商都可以(并且通常会)提供自己的拨号器应用程序。因此,您需要知道拨号器应用程序的包名称。以下是解决这个问题的方法:
// Ask the PackageManager to return a list of Activities that support ACTION_DIAL
PackageManager pm = getPackageManager();
Intent intent = new Intent(Intent.ACTION_DIAL);
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
List<String> packageList = new ArrayList<String>();
if (list != null) {
// For each entry in the returned list, get the package name and add that to a list (ignore duplicates)
for (ResolveInfo r : list) {
String packageName = r.activityInfo.packageName;
if (!packageList.contains(packageName)) {
packageList.add(packageName);
}
}
}
// Get a launch Intent for each package in the list
final List<Intent> launchIntents = new ArrayList<Intent>();
for (String p : packageList) {
intent = pm.getLaunchIntentForPackage(p);
if (intent != null) {
launchIntents.add(intent);
}
}
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (launchIntents.size() > 0) {
// Get the first launch Intent. If there are more than 1, we don't know how to choose!
Intent intent = launchIntents.get(0);
startActivity(intent);
} else {
// Couldn't find an way to launch the dialer
}
}
});
如果用户安装了多个可以响应DIAL操作的应用,则仍会出现问题。你需要找出一种选择正确方法的方法。我将此作为练习留给读者。
感谢您提出这个问题,它让我有机会为您找到解决方案:-D