I am running a foreground service in android 10 and 11. But I have issue in my Oppo android 11. Issue is that the execution of any process is stopped after some time because the Allow Background Activity is not enabled for this app in setting. If I allow it then the foreground service works fine. I don't know how to check that if the Allow background activity is enabled or not and how to move to that specific intent. I have search alot but didn't found any solution.
The picture of the app setting is here.
The picture of the app setting is here
The Android Manifest file permissions are here.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<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" />
Related
I am trying to use the TelephonyManager class to read the line1Number and the IMEI of the Sim card in the respective slots. I have also tried using TelecomManager class to achieve the same with zero success. I headed over to the official documentation of the c;class on Google documentation and did find out that the methods TelephonyManager.GetLine1Number() or TelephonyManager.GetImei() can only be used if one of the following conditions is met.
If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this is a privileged permission that can only be granted to apps preloaded on the device.
If the calling app is the device owner of a fully-managed device, a profile owner of an organization-owned device, or their delegates (see DevicePolicyManager.getEnrollmentSpecificId()).
If the calling app has been granted the Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER permission.
If the calling app is the default SMS role holder (see RoleManager.isRoleHeld(java.lang.String)).
If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this is a privileged permission that can only be granted to apps preloaded on the device.
I am aware that as from Android 10 accessing device identifiers is kind of technical so because they said if one of the requirements above is met then a method like TelephonyManager.GetImei() should work when invoked. I did try to use a method from an app with device administration privileges like mentioned in the second requirement from the list above, the exception user 10711 does not meet the requirements to read device identifiers is thrown. I also tried the other requirement to declare the permission <uses-permission android:name="android.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER"/> in my manifest and then tried to request for the permission at runtime from the user like below
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.UseIccAuthWithDeviceIdentifier) !=
Permission.Granted)
{
RequestPermissions(new string[]{Manifest.Permission.UseIccAuthWithDeviceIdentifier},682);
}
Meeting that permission requirement also does not make the invocation of the TelephonyManager.GetImei() work. How do I write code that will make devices running Android 10 and above return the IMEI and lineNumber without the exception does not meet the requirements to access device identifiers being thrown?
My manifest file looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="LockScreenAPI.LockScreenAPI">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER"/>
<application android:allowBackup="true" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme">
</application>
</manifest>
An answer in Android Java is accepted because I use it as the blueprint to implement in a Xamarin Android app, Thank You.
I've been facing an issue for a few days now. Everytime I submit my release to Google Play Store, I get a message saying my app has been rejected over and over again. I tried multiple things.
First I tried removing the permissions from my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.lachariottenative">
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
</manifest>
Then I tried editing my app.json file and set permissions to an empty array but each time I get the same error when uploading my app to the Google Play Store. It says that I'm using background location although I am not.
Can you help please?
Thanks in advance
EDIT : I do not wish to use location in my app for the moment. But somehow it still asks for permissions...
In my app I play some music and as any other music apps, I should stop music when the user receive a call, so, I use this permission for that:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I use the permission for control the telephony manager.
I know some tablets devices doesn't have phone feature so for that Google Play Store filtered my app, it considered it as an app compatible only with devices which is contains phone feature.
With some search I edited my code:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
And in MainAcitivty :
if (Build.VERSION.SDK_INT >= 23) {
PackageManager pm = getApplicationContext().getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
checkPermission();
if (!checkPermission()) {
requestPermission();
}
}
}
My Question: after this edit, will my app show up in tablets store or should I should do something else?
This might be enough, but you should make sure you are following all the Tablet app quality guidelines.
I'm trying to publish a message via MQTT. So I created a blank Android app and added the Paho MQTT library to it.
This is the line of code I execute first:
MqttClient client = new MqttClient("tcp://192.168.178.34", "Foo");
This throws an "MqttException" which contains no message, no error code, no nothing. So currently I have no idea what's going wrong.
I also added the following permissions to my app:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Can anyone give me a hint what I could be doing wrong here?
In the code, The activated class is the TCPNetworkModule class which is using connect method of the socket class directly(see the start method of the class).
I think the exception might be the NetworkOnMainThreadException
attempting to use blocking IO.
That's why we use MqttAndroidClient instead.
I wrote an app that detects wifi networks and when I press on a network it gives me detailed info about that network. Now the problem is that I wrote it 3 years ago when Android KitKat did not require the popup permission from the user and now when I run it on android N and I press scan it neither scans nor gives me the pop-up permission.
I have not programmed android for a long time and I don't know the changes in Android app coding requirements . Any ideas why this happens?
Current permissions used by the app:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
In order to get WiFi scan results on Marshmallow and later, your app will need to request the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, and the Location Mode setting must be enabled as well.
From the documentation for getScanResults():
the list of access points found in the most recent scan. An app must
hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in
order to get valid results
This change was made due to the fact that location can be determined from WiFi scan results.
As an extra security measure, apps now need to request the Location permission in order to see WiFi scan results, and additionally if the user sets their Location Mode to off, no app can see scan results when running in the background.
So, at a bare minimum, add the ACCESS_COARSE_LOCATION permission to your manifest in order to get WiFi scan results:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
If you keep your target API version lower than 23, you can't request permissions at runtime. In this case, your app will continue to request all permissions at install time.
If you update your app to target API version 23 or later, you will need to request all dangerous permissions at runtime. See here for an example of requesting the Location permission at runtime.