gpt4 book ai didi

android - 无法对非静态方法 getPackageManager() 进行静态引用

转载 作者:太空狗 更新时间:2023-10-29 16:38:47 35 4
gpt4 key购买 nike

我正在尝试检索 android 中已安装应用程序的列表。我写了下面的代码:

final Intent myIntent = new Intent(Intent.ACTION_MAIN, null);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List AppsList = Context.getPackageManager().queryIntentActivities(myIntent, 0);

我收到这个错误:

Cannot make a static reference to the non-static method getPackageManager() from the type Context

知道ContextPackageManager都是抽象类,无法解决错误。请帮忙。

最佳答案

尝试:

final List AppsList = getApplicationContext().getPackageManager().queryIntentActivities(myIntent, 0);

关于android - 无法对非静态方法 getPackageManager() 进行静态引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21663351/

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