gpt4 book ai didi

java - 从服务启动第三方应用程序

转载 作者:行者123 更新时间:2023-11-30 02:11:57 24 4
gpt4 key购买 nike

我需要从服务启动 Activity 。我尝试使用:

public void openApplication(String packageName){
Intent intent = new Intent(packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}

但我得到这个错误:

E/AndroidRuntime(8563):android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.encrypted flg=0x10000000 }
04-30 11:55:07.507: E/AndroidRuntime(8563): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
04-30 11:55:07.507: E/AndroidRuntime(8563): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)

有什么想法吗?

最佳答案

试试这个代码。您需要为程序包获取启动 Intent:

public void openApplication(String packageName) {
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(packageName);
startActivity(intent);
}

关于java - 从服务启动第三方应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29971302/

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