如何打开拨号器应用程序到主屏幕,该应用程序显示最近的内容和搜索内容(而不是拨号盘)。
我试过context.getPackageManager().getLaunchIntentForPackage("com.android.diler")
但它返回null,com.android.diler
也返回null。
最佳答案
这个怎么样:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
编辑:提供代码以启动拨号程序,就像从主屏幕一样
啊。问题在于,不仅只有一个拨号程序。每个电话制造商都可以(并且通常会提供)自己的拨号程序。因此,您需要知道Dialer应用程序的软件包名称。这是一种解决方法:
// 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
关于android - 在主屏幕上打开拨号器应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26862497/