When should I use ACCESS_COARSE_LOCATION permission?

Do I also need the ACCESS_COARSE_LOCATION permission? No. What’s the use case where I need the coarse location? If you do not ask for ACCESS_FINE_LOCATION, but you need location data, and you are willing for that data to be fuzzy (say, up to around a city block from the user’s position). In the case of … Read more

SYSTEM_ALERT_WINDOW – How to get this permission automatically on Android 6.0 and targetSdkVersion 23

It is a new behaviour introduced in Marshmallow 6.0.1. Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically. If instead the app is sideloaded, the permission is not automatically granted. You can try to download and install … Read more

If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?

https://developer.android.com/guide/topics/location/strategies.html#Permission Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.) In short: yes, you don’t need ACCESS_COARSE_LOCATION if you’ve already defined ACCESS_FINE_LOCATION.

How to request permissions from a Service in Android Marshmallow

requestPermission() can only be called from an Activity and not a Service (unlike checkPermission() that only requires PackageManager). So you need to do some extra work to get around that; you do need to provide an Activity in your app and, for example, your Service can check for permissions it needs and if they have … Read more

WRITE_EXTERNAL_STORAGE when targeting Android 10

A workaround is to actually ignore the warning, as it is just informational and therefore harmless. By setting maxSdkVersion to 28 no need to worry anymore. <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” android:maxSdkVersion=”28″ tools:ignore=”ScopedStorage” /> Note that using the android:requestLegacyExternalStorage flag as stated in other answers is not a solution, is just a temporary patch which will no longer … Read more

How to detect incoming calls, in an Android device?

Here’s what I use to do this: Manifest: <uses-permission android:name=”android.permission.READ_PHONE_STATE” /> <uses-permission android:name=”android.permission.PROCESS_OUTGOING_CALLS”/> <!–This part is inside the application–> <receiver android:name=”.CallReceiver” > <intent-filter> <action android:name=”android.intent.action.PHONE_STATE” /> </intent-filter> <intent-filter> <action android:name=”android.intent.action.NEW_OUTGOING_CALL” /> </intent-filter> </receiver> My base reusable call detector package com.gabesechan.android.reusable.receivers; import java.util.Date; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.telephony.TelephonyManager; public abstract class PhonecallReceiver extends … Read more

Android permission doesn’t work even if I have declared it

(the following is extracted from a blog post of mine about this) The big reason for not getting your permission nowadays is because your project has a targetSdkVersion of 23 or higher, and the permission that you are requesting is “dangerous”. In Android 6.0, this includes: ACCEPT_HANDOVER ACCESS_BACKGROUND_LOCATION ACCESS_MEDIA_LOCATION ACTIVITY_RECOGNITION ANSWER_PHONE_CALLS ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ADD_VOICEMAIL BODY_SENSORS … Read more

Android 6.0 multiple permissions

Just include all 4 permissions in the ActivityCompat.requestPermissions(…) call and Android will automatically page them together like you mentioned. I have a helper method to check multiple permissions and see if any of them are not granted. public static boolean hasPermissions(Context context, String… permissions) { if (context != null && permissions != null) { for … Read more

Android marshmallow request permission?

Open a Dialog using the code below: ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1); Get the Activity result as below: @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 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)