TEL:400-8793-956
当前位置:程序、服务器

如何从应用程序禁用(删除)权限

提问者: 近期获赞: 浏览人数: 发布时间:2021-02-01 12:26:01

 问:我想从我的应用中禁用(删除)这些权限

 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
在我的应用程序中禁用使用相机拍摄照片和用户权限的源代码,我正在使用android studio。
 
那就是来源,新的将会如何?
 
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bpositive"
    android:versionCode="2"
    android:versionName="1.0.3" >
    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="25" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" /> <!-- Permissions required for GCM -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <permission
        android:name="com.bpositive.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.bpositive.permission.C2D_MESSAGE" />
    <application
        android:name="sample.bpositive.sparkleappz.app.BPlus"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="sample.bpositive.sparkleappz.activities.SplashActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="sparkleappz.com/"
                    android:scheme="http" />
                <data
                    android:host="sparkleappz.com/"
                    android:scheme="https" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="sample.bpositive.sparkleappz.activities.MainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <activity
            android:name="sample.bpositive.sparkleappz.activities.ResetPasswordActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <activity
            android:name="sample.bpositive.sparkleappz.activities.DonateActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <service android:name="sample.bpositive.sparkleappz.MyFirebaseMessagingService" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name="sample.bpositive.sparkleappz.MyFirebaseInstanceIDService" >
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar" /> <!-- Include the AdActivity and InAppPurchaseActivity configChanges and themes. -->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
        <activity
            android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity"
            android:theme="@style/Theme.IAPTheme" />
        <activity
            android:name="com.google.android.gms.appinvite.PreviewActivity"
            android:exported="true"
            android:theme="@style/Theme.AppInvite.Preview" >
            <intent-filter>
                <action android:name="com.google.android.gms.appinvite.ACTION_PREVIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.android.gms.common.api.GoogleApiActivity"
            android:exported="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <!--
 FirebaseMessagingService performs security checks at runtime,
             no need for explicit permissions despite exported="true"
        -->
        <service
            android:name="com.google.firebase.messaging.FirebaseMessagingService"
            android:exported="true" >
            <intent-filter android:priority="-500" >
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
            android:enabled="true"
            android:exported="false" >
        </receiver>
        <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
            android:enabled="true"
            android:permission="android.permission.INSTALL_PACKAGES" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>
        <service
            android:name="com.google.android.gms.measurement.AppMeasurementService"
            android:enabled="true"
            android:exported="false" />
        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.bpositive" />
            </intent-filter>
        </receiver>
        <!--
 Internal (not exported) receiver used by the app to start its own exported services
             without risk of being spoofed.
        -->
        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
            android:exported="false" />
        <!--
 FirebaseInstanceIdService performs security checks at runtime,
             no need for explicit permissions despite exported="true"
        -->
        <service
            android:name="com.google.firebase.iid.FirebaseInstanceIdService"
            android:exported="true" >
            <intent-filter android:priority="-500" >
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <provider
            android:name="com.google.firebase.provider.FirebaseInitProvider"
            android:authorities="com.bpositive.firebaseinitprovider"
            android:exported="false"
            android:initOrder="100" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
</manifest>
 
 
答:当我浏览了您提供的信息后,您只需要从清单文件中删除WRITE_EXTERNAL_STORAGE和READ_EXTERNAL_STORAGE权限,并从您的android项目中删除运行时权限代码。
权限是指允许官方做特定的事情,例如访问您的数据,位置等。因此,运行时权限是相同的,在Android中,当我们运行/打开任何应用程序时,它都要求获得访问我们的照片/画廊,位置,联系人等的权限,因此允许或不允许这种许可的选项称为运行时许可。
 
从API级别26(Android 6.0)开始,要求用户允许或拒绝App请求的其他权限。以前是在安装应用程序时完成的。它为用户提供了对应用程序的更多控制权,以保护他们的隐私。
 
 
 
由于相同而面临的复杂性:
 
从片段管理权限回调很困难。
它要求在代码的任何地方进行适当的检查,以确保相同。
增加代码的复杂性。
 
 
因此,由于上述难题,我想出了一个新的库,该库可以处理所有运行时权限,而无需为其编写额外的代码,也无需在各处应用检查。
 
该 RuntimePermission的库处理所有的权限,通过阅读你的清单,并处理每一个请求,如果它需要运行许可与否。
 
 
 
当前,该库托管在Maven Central上,因此您可以从以下编译语句通过maven获得它。
 
compile 'com.app.runtimepermission:runtimepermission:0.0.4'
 
 
现在调用构造函数,并按如下所示添加活动上下文和侦听器的传递
 
// to get single permission 
PermissionHandler.getPermission(getActivity(), Manifest.permission.READ_CONTACTS, new PermissionListener() {
            @Override
            public void onGranted(String message) {
                Log.e(TAG, message);               
            }
            @Override
            public void onError(String errorMessage) {
                Log.e(TAG, errorMessage);
            }
            @Override
            public void onRejected(String message) {
                Log.e(TAG, message);
            }
        });
// to check if permission is critical or not
         boolean value  = PermissionHandler.isCriticalPermission(getContext(),
                Manifest.permission.INTERNET);
        Log.e(TAG , Manifest.permission.INTERNET+" "+value);
// to get all permissions
        PermissionHandler.getAllPermissions(getActivity(), new PermissionListener() {
            @Override
            public void onGranted(String message) {
                Log.e(TAG, message);
            }
            @Override
            public void onError(String errorMessage) {
                Log.e(TAG, errorMessage);
            }
            @Override
            public void onRejected(String message) {
                Log.e(TAG, message);
            }
        });
 
 
就是这样,您现在就可以走了,一旦获得用户授予的许可,您就会收到消息。另外,您将在与您通话的同一位置获得响应。
上一篇: 如何在Android中一次请求多个权限?
下一篇: 如何使用Java脚本检查页面上被禁止的单词?