gpt4 book ai didi

java - 从应用程序内启动 Android 应用程序

转载 作者:行者123 更新时间:2023-11-29 05:23:27 25 4
gpt4 key购买 nike

要启动一个 Android 应用程序,我使用下面的代码,它适用于每个应用程序安装在手机上,除了“电话”应用程序本身。当我尝试启动“电话”时应用程序未启动,没有错误消息或显示或抛出异常。

这是我用来启动应用程序的代码:

launchApp(context, packageManager,
"com.android.phone");

/*
* Launch an application
*
* @param c Context of application
*
* @param pm the related package manager of the context
*
* @param pkgName Name of the package to run
*/
public static boolean launchApp(Context c, PackageManager pm, String pkgName) {
// query the intent for lauching
Intent intent = pm.getLaunchIntentForPackage(pkgName);
// if intent is available
if (intent != null) {
try {
// launch application
c.startActivity(intent);
// if succeed
return true;

// if fail
} catch (ActivityNotFoundException ex) {
// quick message notification
Toast toast = Toast.makeText(c, "Application Not Found",
Toast.LENGTH_LONG);
// display message
toast.show();
}
}
// by default, fail to launch
return false;
}

这是启动 Android 应用程序的正确方法吗和/或“电话”app 是一种特殊情况,不允许其他应用程序启动/使用它?

最佳答案

试试这段代码:

Intent intent = new Intent(Intent.ACTION_DIAL);

startActivity(intent);

关于java - 从应用程序内启动 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23712455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com