不能让一个静态引用非静态方法getPackageManager() [英] Cannot make a static reference to the non-static method getPackageManager()

查看:1239
本文介绍了不能让一个静态引用非静态方法getPackageManager()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要检索的android安装的应用程序列表。我写了下面的code:

I am trying to retrieve the list of installed apps in android. I have written the following code:

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

我收到此错误:

I am getting this error:

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

知道这两个上下文 PackageManager 是抽象类,不能纠正错误。请帮助。

Knowing that both Context and PackageManager are abstract classes, cannot resolve the error. Kindly help.

推荐答案

尝试:

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

这篇关于不能让一个静态引用非静态方法getPackageManager()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆