我的Android清單給出的是這樣的:Android Studio中請求許可,即使它在Android清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.regnav.stilla" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
當我嘗試使用它是Android清單這樣的權限:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
Location location = locationManager.getLastKnownLocation(provider);
它會告訴我,我需要做的權限檢查,像這樣:
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// public void requestPermissions(@NonNull String[] permissions, int requestCode)
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
我覺得這是斯特拉nge,因爲我的Android清單已經允許我這樣做..我做錯了什麼?
我在編輯工作地點Android清單:
Stilla /應用/ src目錄/主/ AndroidManifest.xml中
我到底做錯了什麼?
您是否正在Android 6.0運行您的應用程序? –
並顯示你的logcat。 –
我忘記補充說,代碼總是進入「if(checkselfpermission ..」,即使我已經在AndroidManifest中給予權限 – Regnav