简体   繁体   English

如何获取在Android中以编程方式使用位置的应用列表?

[英]How to get list of apps that use location programmatically in Android?

I'm developing an app on Android OS. 我正在Android操作系统上开发应用程序。

I need a method that returns the list of apps that rely on location services/GPS 我需要一种方法来返回依赖位置服务/ GPS的应用程序列表

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. 然后搜索有关位置服务(如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"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在android中如何以编程方式列出使用数据连接的应用程序? - In android how to programmatically list the apps that use Data connection? Android:如何获取使用Internet访问的已安装应用程序列表-PackageManager - Android : How to get the List of Installed apps that use Internet Access - PackageManager 如何以编程方式获取运行 Android 7.0 的设备中已安装浏览器应用程序的列表? - How to get the list of installed Browser Apps in an Android 7.0 running devices programmatically? 如何以编程方式从Android的默认应用列表中删除应用? - How to programmatically remove app from Default Apps List for android? 如何以编程方式获取当前在 android 最近堆栈中的应用程序的名称? - How to programmatically get the names of apps that currently are in the recents stack of android? 如何获取 Android 设备上已安装应用程序的列表 - How to get a list of installed apps on Android device 如何获取Android上“最常用的应用”列表 - How to get list of “most used apps” on Android 如何获取 Android 11 中已安装应用程序的列表 - How to get a list of installed apps in Android 11 如何在Android中以编程方式启用“使用位置?”消息? - How do I programmatically enable the the “Use location?” message in Android? Android:如何在“我的位置”中以编程方式启用“使用无线网络” - Android: How to programmatically enable “Use wireless networks” in My Location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM