Android: what to choose for requestcode values?

Documenting the findings for future reference: The following are code from android.support.v4.app.FragmentActivity /** * Modifies the standard behavior to allow results to be delivered to fragments. * This imposes a restriction that requestCode be <= 0xffff. */ @Override public void startActivityForResult(Intent intent, int requestCode) { if (requestCode != -1 && (requestCode&0xffff0000) != 0) { throw … Read more

How to obtain MANAGE_EXTERNAL_STORAGE permission

Android 10 doesn’t require “android.permission.MANAGE_EXTERNAL_STORAGE”, android:requestLegacyExternalStorage=”true” under application tag in manifest will work. For android 11, try this if (Environment.isExternalStorageManager()) { //todo when permission is granted } else { //request for the permission Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); Uri uri = Uri.fromParts(“package”, getPackageName(), null); intent.setData(uri); startActivity(intent); }

Android 13 – READ_EXTERNAL_STORAGE_PERMISSION still usable

According to documentation (https://developer.android.com/training/data-storage/shared/media#storage-permission): No permissions needed if you only access your own media files On devices that run Android 10 or higher, you don’t need any storage-related permissions to access and modify media files that your app owns, including files in the Media Store. Downloads collection. If you’re developing a camera app, for example, … Read more

Android : Permissions check for BLE [closed]

Google made Android more strict by adding the new BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions. You will get SecurityException in runtime if you attempt to access any BLE API that requires these permissions. So we need to check the permissions in the activity which is set to android.intent.action.MAIN in the manifest file. I call that as MainActivity. … 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

Answer Incoming Call in Android 6.0

Hope this will help some one 🙂 public void acceptCall() { if (Build.VERSION.SDK_INT >= 21) { Intent answerCalintent = new Intent(context, AcceptCallActivity.class); answerCalintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); answerCalintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(answerCalintent); } else { Intent intent = new Intent(context, AcceptCallActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } AcceptCallActivity.java import android.app.Activity; import android.app.KeyguardManager; import android.content.BroadcastReceiver; import … Read more

BroadcastReceiver SMS_Received not working on new devices

Okay the problem was resolved. The issue did not reside with priorities, but with my phone being a Nexus 6P (a.k.a. API 23). Providing permissions in the manifest.xml alone wasn’t enough and I had to add code for runtime permission request. See Android documentation for runtime permissions Add this code to your MainActiviy: ActivityCompat.requestPermissions(this, new … Read more

Android 6.0 Permission Denial: requires permission android.permission.WRITE_SETTINGS

In API 23 or higher user has to authorize manually for this permission, you can check by calling- ‘Settings.System.canWrite’ below is the implementation for this:- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.System.canWrite(context)) { // Do stuff here } else { Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse(“package:” + getActivity().getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }