我已经添加了ACCESS_FINE_LOCATION但仍然出现错误
Looks like the app doesn't have the permission to access location.
Add the following line to your app's AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
这是我的AndroidManifest.xml文件
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
请帮助。
答案 0 :(得分:1)
您需要在清单中添加 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
和 String permission = android.Manifest.permission.ACCESS_FINE_LOCATION;
if (ActivityCompat.checkSelfPermission(SearchCityClass.this, permission)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.
checkSelfPermission(SearchCityClass.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(SearchCityClass.this, "Permission not granted", Toast.LENGTH_SHORT).show();
ActivityCompat.requestPermissions(SearchCityClass.this, new String[]
{permission}, requestCode);
}
权限
确保您已在清单文件中添加了权限
assets/levels/merkur/level1.gbl
如果您的目标是Android api 23及以上,则必须要求 run-time permission
因为从Android 6.0(API级别23)开始,用户在应用运行时向应用授予权限,而不是在安装应用时授予权限。
充足的代码
if (Gdx.files.internal("levels/merkur/level1.gbl").file().exists())
答案 1 :(得分:1)
在SDK版本23之前的设备上,如果权限出现在清单中,则会自动授予权限,因此请检查并且请求应始终为true。
如果用户之前已关闭您提示的权限,操作系统会建议您的应用显示需要该权限的理由。可选的基本原理参数仅在必要时显示对话框提示 - 否则,将显示正常的权限提示。
import { PermissionsAndroid } from 'react-native';
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.ACCESS_FINE_LOCATION,
{
'title': 'Location Permission Permission',
'message': 'App needs access to your Location ' +
'.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the Location")
} else {
console.log("Location permission denied")
}
} catch (err) {
console.warn(err)
}
}