简体   繁体   中英

How do I get permissions only in AndroidManifest.xml file for installed apps in android device?

I'm developing an android application that can do permission-based searches. I have a code that takes and parses AndroidManifest.xml files in apk files.

This code parses the xml file and outputs an result like this:

android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET

I have a model called PInfo. This model has an ArrayList named permissions. When you get permissions with "PackageInfo" on Android, it gives the following results.

android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
android.permission.WAKE_LOCK
com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE
com.google.android.c2dm.permission.RECEIVE
android.permission.READ_EXTERNAL_STORAGE

AndroidManifest.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.omfaer.minion">
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_CONTACTS" />
        <uses-permission android:name="android.permission.WRITE_CONTACTS" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name="com.omfaer.minion.activities.MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

            <activity
                android:name="com.omfaer.minion.activities.HomeActivity"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>

            <activity android:name=".activities.WallpapersActivity"/>

            <provider
                android:exported="false"
                android:grantUriPermissions="true"
                android:authorities="${applicationId}.provider"
                android:name="android.support.v4.content.FileProvider">

                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/provider_path"
                    />

            </provider>
        </application>

    </manifest>

PackageInfo code:

    List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(context.getPackageManager().GET_PERMISSIONS);

    for (int i = 0; i < packs.size(); i++) {
        PackageInfo p = packs.get(i);

        PInfo deviceApps = new PInfo();
        deviceApps.appName = p.applicationInfo.loadLabel(context.getPackageManager()).toString();
        deviceApps.appPackage = p.packageName;
        deviceApps.appIconId = p.applicationInfo.icon;
        StringBuilder strBuilderPermissions = new StringBuilder();
        try {
            if (p.requestedPermissions != null) {
                for (String perms : p.requestedPermissions) {
                    deviceApps.permissions.add(perms);
                }
            }
        } catch (Exception e) {
            //Log.v("PUCA for  add permissions ", e.toString());
        }
    }

I want to get this result also on the Android side.

android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET

This should provide accurate results for thousands of applications. How can I do?

According to official docs :

Your APK file can contain just one AndroidManifest.xml file, but your Android Studio project may contain several—provided by the main source set, build variants, and imported libraries. So when building your app, the Gradle build merges all manifest files into a single manifest file that's packaged into your APK.

The manifest file you attached is your manifest but when android compiling your project it will merge other manifests into your manifest. for example if you implement a library its manifest will merge into yours in apk file. for finding manifest file of your apk try to decompile it ( here ) and read that file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM