can anybody explain me what is this error ? I am getting only for android 4 + and not for below:
E/AndroidRuntime(891): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getaddress/com.example.getaddress.MainActivity}: java.lang.IllegalArgumentException: requested provider network doesn't exisit
It appears that the NETWORK_PROVIDER location provider is not accessible in Android 4+ emulators without Google APIs (well actually I have not tested on all of them ,see below). The real devices I have tested on are OK with it (but they all have Google services on them, it would be interesting to test with custom, clean Android versions, maybe with Kindles?).
It is not a question on enabling/disabling the provider in the device settings, it is simply not there in the emulator.
Symptom
Basically this code:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,mLocListener);
will cause the following exception:
java.lang.IllegalArgumentException: provider doesn't exisit: null
on all Android 4+ naked emulators (as opposed to Google-bound emulators)
note: the typo in "exisit" is in the actual log line.
Diagnostic
Getting a list of all location providers on the target device with the following:
List<String> providers = locationManager.getAllProviders();
I can see that the network provider is present on
physical devices
android 2.3.3 emulator (no Google APIs)
android level 17 (4.2) emulator (with Google APIs)
But not on
android level 15 (4.0.3) emulator with Google APIs
android 4.2 emulator (no Google APIs)
My guess is that for non-technical reasons, Google has not allowed the network location service in AOSP and limited its usage to the Google-bound versions of the OS from 4.2 (?).
What I don't know if whether or not there is a replacement network location service on non-Google devices (such as Kindle).
Probable impact on your app
I would not expect this to have any impact on most smartphones and tablets. However it can
somewhat impair your ability to test
be a compatibility issue for users that use custom/non-Google versions of Android (once again, Kindle?)
How to detect
A simple test such as:
locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)
can tell you painlessly if the network provider is present on the device. Note that if it is present, but the user has not activated it, your LocationListener will receive an onProviderDisabled callback following the location request.
Related
I'm developing an app that uses Nearby Connections API with basic P2P strategy. Suddenly, weirdly enough I'm not able to advertise and discover devices on my Pixel 3a with newest Android 12 and Play Services. OnFailureListeners throw these exceptions:
for discovering: 8037: unknown status code: 8037
for advertising: 8038: unknown status code: 8038
Indeed they cannot be found in docs and source code.
I also checked Google's "Rock Papers Scissors" official sample and it throws the same error codes.
Of course I reinstalled the app and restarted & updated my phone. EDIT: I also did the factory reset and it didn't help. But after I downgraded to latest Android 11 using Android Flash Tool, it started working again. Moreover, everything still works fine on Android 11, 10 and 9 using different phones.
Any ideas what causes this issue? It just worked fine for last two weeks and stopped working today. I believe it needs some deep investigation in source code (Xlythe if I may ask for your help, that would be really great).
After a while I finally managed to find a solution. It looks like Nearby Connections (all Nearbys?) have a critical bug on Android 12 that happens non-deterministically (API can work fine for few weeks then suddenly will throw these errors for another few weeks).
This bug is related to Android 12's feature change related to Bluetooth. Quoting:
Android 12 introduces the BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE, and BLUETOOTH_CONNECT permissions. These permissions make it easier for apps that target Android 12 to interact with Bluetooth devices, especially for apps that don't require access to device location.
In other words, some Bluetooth permissions are now legacy and there are some new permissions that are mandatory to make the API work. And you need to handle both scenarios in your code (before and after Android 12).
So here's a quick "mapper" from error codes to Manifest's permissions:
Error code 8037 while discovering - you haven't granted permission
for BLUETOOTH_SCAN
Error code 8038 while advertising - you haven't granted permission for BLUETOOTH_ADVERTISE
Error code 8039 (that's a new one as well) while onEndpointFound - you haven't granted permission for BLUETOOTH_CONNECT
More information how to implement new permissions properly can be found in documentation.
And I'm still waiting for Google to fix it in next Nearby API update as this is a little bit of workaround. Adding proper error messages to codes might be a little work to do but I would also revise if other permissions are still required after Android 12's update.
I cant get serial on android 10 device.
I know about everything(permission, runtime permissions, I get serial only after the permission is granted) from here
android Build.GetSerial() throwing exception
My code works on all android versions, except 10
Do you have any ideas?
If you follow the official documentation here: https://developer.android.com/reference/android/os/Build.html#getSerial(), more info on Android 10 changes here
You will notice that starting from Android 10 this method is returning Build.UNKNOWN. You can't use it to uniquely identify a single device anymore
You need to switch to the "less" persistent version called Settings.Secure.ANDROID_ID
The only ways to bypass this restriction are:
Create a system app to be able to get the READ_PRIVILEGED_PHONE_STATE system permission (a normal app can't get this).
Be registered as a carrier (which requires you to have built the Android ROM)
Have a custom "work profile" to set your own policies in the device.
As you can imagine, all those options are not meant to be used by standard android app developers
I have a flutter app, that uses the location library, found here
I import with
import 'package:location/location.dart';
and later call with
location.onLocationChanged().listen((Map<String,double> currentLocation) {
print("LocationListener " + currentLocation.toString());
}
This works fine when run on an avd phone emulator, and also on a real phone. I get periodic updates with new gps locations coming through.
However, I want to get this working on an Android Wear 2 device/watch.
If I try it in either an emulator or actual android watch (Huawei watch 2), the stream never seems to trigger. I'm also trying to update the location via the emulator, which again works with a phone, but doesn't work with a watch.
The adv device I'm trying is Android Wear Round API 26.
The actual device is
Wear OS By Google 1.6, Google Play Services 14.3.67, android o.s 8.0
Location is enabled on the phone. It's possible the avd watch location is expecting it from a phone, but the actual watch device isn't, as it can work standalone, and things like Google Maps work fine with it GPS wise.
Does Android Wear 2 treat GPS/listeners different in anyway that I should be aware of, and any way to get that working ?
I've got this working finally as I hadn't realised permissions requirements had changed, as per here.
So I've added one of these...
<!--<uses-permission android:name="android.hardware.location.gps" />-->
<uses-permission android:name="android.hardware.location" />
location permission seems to work, but you can add gps specifically if that is required.
I have created an Android app that runs on a Samsung Galaxy Tab Pro (SM-T900). The main feature of this app is RS232/USB communication using the USB host mode and the USB-to-Serial library.
This app has been working perfectly without the need for any code updates for over a year. However, since the latest Samsung/Android update to Android 5.1, I get a security error and I am no longer able to communicate with USB/RS232 devices. Apart from that, my app runs fine without any crashing. I am simply no longer able to perform USB/RS232 communication.
Here's the logcat:
03-24 17:03:09.015 2798-3149/? D/UsbSettingsManager: requestPermission:/dev/bus/usb/002/008 ,packageName com.example.pumpconnector ,pi PendingIntent{338f59ea: PendingIntentRecord{1fd58866 com.example.pumpconnector broadcastIntent}}
03-24 17:03:09.020 2798-3149/? D/ApplicationPolicy: isUsbDevicePermittedForPackage vendorId: 1027, productId: 24577, package: com.example.pumpconnector
03-24 17:03:09.020 13313-13332/com.example.pumpconnector V/MainActivity: java.lang.SecurityException: Admin does not have android.permission.sec.MDM_APP_MGMT
The app has been configured to start whenever a USB device is attached to the device, which still works on the Samsung tablet. The app works perfectly fine on other (non-Samsung) devices. It's fully functioning on a LG Nexus 5 with Android 6.0.1. installed and also on a Moto G with Android 5.1. A little Google search on the exception quickly points to Samsung specific update/bug that prevent USB communication (check this thread).
I tried to put the following line in the Manifest (without result):
<uses-permission android:name="android.permission.sec.MDM_APP_MGMT"/>
Is there any way to get my app to get the android.permission.sec.MDM_APP_MGMT without having to wait for Samsung to fix it? All help is appreciated.
Check Knox version on device (maybe have been upgraded between) and follow migration guide in knox web site.
Also be sure you'r validating KLM license using KnoxEnterpriseLicenseManager and using EnterpriseLicenseManager For Basic License. Ofc you should check for license in receiver with convenient manager.
I have an Android app that should list all installed apps on a device (no root). I have tried both getInstalledApplications(0) and getInstalledPackages(0) methods of PackageManager, but on some devices, which do apparently have too many apps installed, I'm getting "Package manager has died" RuntimeException (I receive them via error reporting service of Google Play). This is due to a well-known limitation of 1MB per 1 call in IPC used internally by Android.
How to workaround this? I don't mind to request the long list by chunks, but I don't see any means for that. Only 2 abovementioned methods are available.
The issue has been fixed since Android 5.1. You may find details in the Android issuetracker.