Posts

Showing posts with the label Android Permissions

Accessing External Storage In Android API 29

Answer : On Android 10 Environment.getExternalStorageDirectory() and Environment.getExternalStoragePublicDirectory() will return storage paths but paths are not readable or writable. For Android 10 you can continue to use paths provided by Environment.getExternalStorageDirectory() and Environment.getExternalStoragePublicDirectory() if you add android:requestLegacyExternalStorage="true" to application tag in manifest file. At runtime your app can call Environment.isExternalStorageLegacy() to check if the request has been done. Another (not known) possibility (only for Android 10) is to add <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> to manifest file. The user has to go to the advanced settings of the app and enable from Advanced settings Install unknown apps | Allow from this source . The nice thing with this is that the user can switch the access rights. You can make it easier for the user if you implement an int...

"Allow All The Time" Location Prompt Not Coming In Android SDK 29

Answer : In order to access the location in background on device running Android 10 (API level 29) or higher, you also need to use below permission in the manifest file <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> please refer the below link for more information https://developer.android.com/training/location/permissions?hl=fr Add "ACCESS_BACKGROUND_LOCATION" in manifest and permissions array. If you only add permission in manifest then "Allow all the time" options will not be shown. You need to add in array to ask users to grant at runtime. In manifest: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> In your activity: if (ContextCompat.checkSelfPermission( this.applicationC...

Android ACTIVITY_RECOGNITION Permission SDK 28 Running On Android 10/Q (SDK 29)

Answer : Solved: In App Api Level 28 + <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/> The app should check if the permission is granted already: if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) { // Permission is not granted } To request the permission: ActivityCompat.requestPermissions(thisActivity, arrayOf(Manifest.permission.ACTIVITY_RECOGNITION), MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION); Learn more about requesting Android runtime permissions. If your app targets SDK level 28 or below, it must specify the com.google.android.gms.permission.ACTIVITY_RECOGNITION permission in its manifest file. Not sure if it helps for your issue but it helps us with similar problem. First check if your app/user has Physical activity permitted - most probably not. If you permit it - your code should run w...

Allow Multiple Run Time Permission

Answer : First parameter is android.app.Activity type, You can't pass context at this place so use this instead of context like below code :- if (ActivityCompat.shouldShowRequestPermissionRationale (this, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale (this, WRITE_EXTERNAL_STORAGE)|| ActivityCompat.shouldShowRequestPermissionRationale (this, CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale (this, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale (this, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_SMS))

Android M Camera Intent + Permission Bug?

Answer : I had the same issue and find this doc from google: https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE "Note: if you app targets M and above and declares as using the CAMERA permission which is not granted, then atempting to use this action will result in a SecurityException." This is really weird. Don't make sense at all. The app declares Camera permission using intent with action IMAGE_CAPTURE just run into SecurityException. But if your app doesn't declare Camera permission using intent with action IMAGE_CAPTURE can launch Camera app without issue. The workaround would be check is the app has camera permission included in the manifest, if it's , request camera permission before launching intent. Here is the way to check if the permission is included in the manifest, doesn't matter the permission is granted or not. public boolean hasPermissionInManifest(Context context, String permissionName)...