本文介绍了如何获取在Android中以编程方式使用位置的应用列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Android操作系统上开发应用程序.
I'm developing an app on Android OS.
我需要一种返回依赖于定位服务/GPS的应用程序列表的方法
I need a method that returns the list of apps that rely on location services/GPS
推荐答案
您可以使用代码(来自)以获取设备上已安装应用的权限列表.然后搜索有关位置服务(如ACCESS_FINE_LOCATION)的必需权限.您的代码将如下所示:
You can use the code (from here) to get list of permissions of installed apps on the device. Then search for the required permissions about location services like ACCESS_FINE_LOCATION.Your code would be something like this:
PackageManager pm = getPackageManager();
List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
try {
PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;
if(requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
Log.d("test", requestedPermissions[i]);
//////////////////////////////////////
//////////////////////////////////////
// Look for the desired permission here
//////////////////////////////////////
//////////////////////////////////////
}
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
为此,您需要在清单中添加以下内容:
And to do so, you need the following in your manifest:
<uses-permission android:name="android.permission.GET_TASKS"/>
这篇关于如何获取在Android中以编程方式使用位置的应用列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!