I'm trying to comply with the Google requirements to request the permission ACTIVITY_RECOGNITION, for Android 10, but I don't seem to understand why there's no permission popup showing , like with the other permissions (ie, Location, storage,...)
The code I have is:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) {
Log.d("TAG", "PERMISSION 'ACTIVITY_RECOGNITION' NOT GRANTED");
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACTIVITY_RECOGNITION},
MY_PERMISSIONS_ACTIVITY_RECOGNITION);
} else
{
Log.d("TAG", "PERMISSION 'ACTIVITY_RECOGNITION' GRANTED");
}
And I'm always ending up on the 'NOT GRANTED' flow, but the ActivityCompat.requestPermissions is not showing no popup!
Is there anything else I'm Missing ?
The manifest contains the
and the app.gradle
minSdkVersion 29
targetSdkVersion 30
Running out of ideas, any help would be welcome.
Just to add, I'm running this on my Pixel 2, with the latest firmware available 10.0.0 (QP1A.191105.004, Nov 2019)
check : Privacy changes in Android 10
From API 29(Android Q, Android 10)
Android App need permission in AndroidManifest.xml
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
Before API 29 AndroidManifest.xml
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
check : Google Fit APIs
And
If the system-auto grants the android.permission.ACTIVITY_RECOGNITION permission, your app retains the permission after you update your app to target Android 10. However, the user can revoke this permission at any time in system settings.
Thanks.
Related
i have xamarin forms app that have tracking and fore ground service for background tracking working fine when set android target api level 28 but after upgrade it target api level 29 to upload app to play store no background location permission set to app so cannot get location when app in background.
and this manifest Permissions:
<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_MOCK_LOCATION" />
and this run time request in main activity:
private static string[] _initialPerms ={
Manifest.Permission.AccessFineLocation,
Manifest.Permission.AccessCoarseLocation
};
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == Permission.Denied || ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Denied)
{
RequestPermissions(_initialPerms, 1337);
}
thanks.
From Android 10, background location came as an independent resource. Apps have to request explicitly this permission besides the foreground one.
#TargetApi(29)
private fun Context.checkLocationPermissionAPI29(locationRequestCode : Int) {
if (checkSinglePermission(Manifest.permission.ACCESS_FINE_LOCATION) &&
checkSinglePermission(Manifest.permission.ACCESS_COARSE_LOCATION) &&
checkSinglePermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) return
val permList = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION)
requestPermissions(permList, locationRequestCode)
}
private fun Context.checkSinglePermission(permission: String) : Boolean {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}
The permission ACCESS_BACKGROUND_LOCATION is new after Android 10.0 . Even if you have set the target version to Api 29 , but the version of support SDK in Xamarin.Android is still v28.x.x.x (Android 9.0) .So this enumeration is still unavailable in Xamarin.Android now . What you need is just to wait the update of the support SDK .
In your case , ACCESS_BACKGROUND_LOCATION will compatible with old version .
If the application apply for ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system will automatically add a permission ACCESS_BACKGROUND_LOCATION during building.
===========================Update===============================
On Android 10 (API level 29) and higher, you must declare the ACCESS_BACKGROUND_LOCATION permission in your app's manifest in order to request background location access at runtime. On earlier versions of Android, when your app receives foreground location access, it automatically receives background location access as well.
<manifest ... >
<!-- Required only when requesting background location access on
Android 10 (API level 29) and higher. -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
More info refer to android document here.
I am learning about request permission on runtime. My phone OS is kitkat. This is my code :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ActivityCompat.requestPermissions(this, arrayOf("com.android.launcher.permission.INSTALL_SHORTCUT"), 1000)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//do something
}
}
}
But permission dialog not shown. Is there any mistakes in my code?
You can not ask runtime permission below Android 6.0
Below Android 6.0 all permisson are granted while user install the app
FYI
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app
Read about runtime permission
Kitkat(version 20)
or below versions of Android don't need runtime permission requests,you can just define the permission in AndroidManifest.xml file and that will be enough for the permissions.
example : <uses-permission android:name="android.permission.CAMERA"/>
BUT
For Lollipop(version 21) or higher version you need to add method to request permissions for your Application.
Android developer site quote,
In Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
Run time permissions are added in Android Marshmallow. Android versions prior to marshmallow will ask for permission during the app installation.
Check this to learn more about android runtime permissions
According to the google developer page:
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
Which means that your phone are required to ask for runtime permissions from API level-23, i.e, Marshmallow whereas KitKat is API level-19. So, no runtime permission will be asked by the Operating system.
I'm not sure i fully understand this. So, for the <= 21 API version we can just use AndroidManifest.xml to request permissions, but Lollipop and higher APIs we have Requesting permission on runtime feature. So i'm using it with this simpe code:
if (Build.VERSION.SDK_INT >= 23) {
mPermissionsToBeAsked.clear();
for (String permission : AudioRecordingThread.PERMISSIONS_NEEDED) {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
mPermissionsToBeAsked.add(permission);
}
} ....
Then, if that list is not empty i'm requesting them :
if (mPermissionsToBeAsked.size() > 0) {
requestPermissions(mPermissionsToBeAsked.toArray(new String[0]), AUDIO_PERMISSIONS_REQUEST_CODE);
}
But, for some reason, on devices, for example, like Samsung Galaxy S7 with Android 6.0.1, all the permissions grandted by default when app is installed. So i want to know why, BUT, it's there is an even bigger concerne, when i go to my application in Application Manager and manually removing Microphone permision, in the app checkSelfPermission(permission) is still returning GRANTED. So the questions:
Why on devices with API level Lollipop and higher all permissions are still granted by default and above code won't add anything into mPersmissionToBeAsked?
Why if i manually removing permission with title MICROPHONE in Application manager checkSelfPermission(android.permission.RECORD_AUDIO) still returns GRANTED?
Just Cross verify in your app gradle file the targetsdk version is greater than 22.
defaultConfig {
// -----
targetSdkVersion 23
//----
}
If it is less than 23 than permission will automatically been granted to your app.
First of all it's Android M and above that handles permission granting. And that means you should have
targetSdkVersion 23
or above. Otherwise the system considers that the developper did not target this version, meaning that the developper does not check for permissions.
I'm trying an application just show Here map on screen. I've followed all of steps in document of Here + provided app_id, app_code, license key + provided 6 permissions in AndroidManifest.xml.
But It got the following issue:
"ERROR: Cannot initialize Map Fragment: MISSING_PERMISSION"
I'm using gradle 2.8, targetSdkVersion 23, compileSdkVersion 23
Android 6 / API 23 has a new permission system, that means you have to request critical permissions from the user.
See Android docs: https://developer.android.com/training/permissions/requesting.html
Just adding the critical permissions to the manifest is not enough anymore.
If you don't want to do this, you can still set traget API level to 22 and work in legacy mode, but to be more future proof, you should implement the new Android6 way of requesting permissions.
The critical permissions in the HERE SDK that you have to request are:
ACCESS_FINE_LOCATION and WRITE_EXTERNAL_STORAGE
Make sure you are using android runtime permission on for location access as from marshmallow onward all the OS need permission to run
I have an app that uses Android AccountManager (package name: com.mycompany.accounts), that adds accounts to the device and provides a login screen. I have another app (com.mycomp.actualapp), that uses the first app to add/remove accounts.
I can successfully add and remove accounts on Pre Marshmallow devices, using the following permissions in the manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
When compiling with sdk 22 and targetting sdk 22, these permissions should be automatically granted. The following code:
accountManager.removeAccount(getAccount(), activity, new AccountManagerCallback<Bundle>() {
#Override
public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
try {
Bundle bundle = accountManagerFuture.getResult();
boolean success = bundle.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
if (success) {
Toast.makeText(activity, activity.getString(R.string.successfully_loggedout), Toast.LENGTH_LONG).show();
afterLogoutSuccess(activity);
} else {
Toast.makeText(activity.getApplicationContext(), activity.getString(R.string.failed_to_logout), Toast.LENGTH_LONG).show();
}
onLogoutListener.onLogoutFinished(success);
return;
} catch (OperationCanceledException e) {
Log.e(TAG,"Operation cancelled exception:", e);
} catch (IOException e) {
Log.e(TAG, "IOException:", e);
} catch (AuthenticatorException e) {
Log.e(TAG, "AuthenticatorException:", e);
}
onLogoutListener.onLogoutFinished(false);
}
}, null);
Fails with the following exception:
java.lang.SecurityException: uid 10057 cannot remove accounts of type: com.mycompany.accounts
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.accounts.IAccountManager$Stub$Proxy.removeAccount(IAccountManager.java:897)
at android.accounts.AccountManager$7.doWork(AccountManager.java:900)
at android.accounts.AccountManager$AmsTask.start(AccountManager.java:1888)
at android.accounts.AccountManager.removeAccount(AccountManager.java:897)
at com.mycomp.actualapp.utils.LoginHelper$4.doInBackground(LoginHelper.java:282)
at com.mycomp.actualapputils.LoginHelper$4.doInBackground(LoginHelper.java:242)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
The strange thing, is that this code runs fine on Pre Marshmallow devices without any issues.
On a side note, I noticed that compiling with sdk 22 and targeting 22: Going to "Settings > Apps > My app(com.mycomp.actualapp) > Permissions" I see only two permissions, "Phone" "Storage".
I noticed that compiling with sdk 23 and targeting 23: I see three permissions, "Phone", "Storage" and "Contacts".
I have tried the following:
Switching to compile with sdk 23 - grant all permissions in app settings, try remove account again. Still fails with the same exception.
Compile with 22 and add the following permissions to the manifest. Make sure all permissions are granted. Still fails with the same exception:
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
I am able to get the users account username and token without additional permission granting, but the removing of accounts doesn't work.
I would really appreciate any help!
I know this is late to answer but I thought I would share my findings in case anyone else is in the same situation.
I upgraded my build to build with 23 instead of 22 as I couldn't solve it on 22. Then I explicitly asking for the permission at runtime to GET_ACCOUNTS before trying to do anything with them.
https://developer.android.com/training/permissions/requesting.html
https://developer.android.com/reference/android/Manifest.permission.html#GET_ACCOUNTS
Further information for compiling with 23: You don't need to ask permission if the app shares the signature of the authenticator that manages an account. In this case, my signatures didn't match so I did need to request it. If you create an account within your app to be used within your app, you do not need to request permission at runtime.
I suddenly was stuck in the same thing yesterday.
In my case, I defined wrong package name in node.
Just fix it and it will work perfectly.
<account-authenticator>
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="Your correct packet name here" + ".accounts"
android:icon="#drawable/ic_launcher"
android:label="xxx"
android:smallIcon="#drawable/ic_launcher"
>
</account-authenticator>
If your package name is:
com.example.android then the account type should be: com.example.android.accounts
Checking in the source code, you can removeAccounts in two cases:
the account is created by your app
your app is a system app
Source: https://android.googlesource.com/platform/frameworks/base/+/05c9ecc/services/core/java/com/android/server/accounts/AccountManagerService.java#1336