使用权限不适用于内置的apk

时间:2018-01-18 11:43:26

标签: android android-studio-3.0

构建我的应用程序时,构建的apk不能正常工作。它只在我的手机上工作。我建立的错误消息是用户权限不可用和安全性异常。它只能在我的手机上工作。

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dineshkumar.panicbutton">

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/welcome"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:exported="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".Welcome"
        android:label="Panic Button"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">

    </activity>
    <activity android:name=".Emergency" />
    <activity android:name=".Contacts" />
    <activity android:name=".ManualCadd" />
    <activity android:name=".Message" />
    <activity android:name=".Guide" />
    <activity android:name=".Updatecontacts" />
    <activity android:name=".ShowContacts" />

</application>

2 个答案:

答案 0 :(得分:1)

你需要实现23&amp;的运行时权限。以这种方式定位设备

ActivityCompat.requestPermissions(MainActivity.this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    1);

对于像这样的句柄

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1: {

          // If request is cancelled, the result arrays are empty.
          if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.          
            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
                Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

更多参考此https://developer.android.com/training/permissions/requesting.html

答案 1 :(得分:0)

您的设备应具有Android 6.0或更高版本以处理运行时权限。此外,您还需要将Target SDK版本设置为23或更高版本,以列出危险权限。