Android Permission Error
I created an application which enables Bluetooth and discovers other devices. In manifest I have the following:
Solution 1:
Try moving the permission outside the <application>
tag. Like below:
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="cajun.meet"android:versionCode="1"android:versionName="1.0"><uses-sdkandroid:minSdkVersion="8" /><uses-permissionandroid:name="android.permission.BLUETOOTH" /><uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/><applicationandroid:icon="@drawable/icon"android:label="@string/app_name"><activityandroid:name=".CajunMeetActivity"android:label="@string/app_name"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".MyULCard"android:label="@string/app_name"></activity><activityandroid:name=".MyULContacts"android:label="@string/app_name"></activity><serviceandroid:name = ".BluetoothExchange"android:exported="true"android:enabled="true"></service></application></manifest>
Solution 2:
Move the uses-permission tags outside of the application element. Uses-permission is a child element of manifest, not application. See the full structure here.
Solution 3:
Move it outside the application:
</application><uses-permissionandroid:name="android.permission.BLUETOOTH" /><uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/></manifest>
See here in docs that uses-permission
is a child of <manifest>
Solution 4:
if using mashmallow version of android then add this code:
this error occur due to security now in api 23 (mashmallow) version android improved there security they ask for permission
if (android.os.Build.VERSION.SDK_INT >= 23) {
// only for gingerbread and newer versionsStringpermission= Manifest.permission.READ_PHONE_STATE;
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, newString[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.READ_PHONE_STATE}, MY_PERMISSIONS_REQUEST_READ_CONTACTS);
} else {
// Add your function here which open camera
}
} else {
// Add your function here which open camera
}
then add this method onRequestPermissionsResult
@OverridepublicvoidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
// If request is cancelled, the result arrays are empty.if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED{ } else { Toast.makeText(getApplication(), "Permission required",Toast.LENGTH_LONG).show(); } return; } }}
Post a Comment for "Android Permission Error"