Nearby Connection : Discovery issues on Android 10 - java

For one of my project I work with Nearby Connection API with P2P_STAR strategy and I experience issue on discovery with Android 10.
I have tested with Huawei devices that resulted in no connection at all with host and on a freshly updated Xiaomi MI 9t who success to connect but disconnect few seconds after with no exceptions...
Before the update it work well on the Xiaomi.
Furthermore, my app work very well on my android 8 or 9 devices.
I tried to add ACCESS_FINE_LOCATION permission and update Google play services without success...
Our project repository : https://github.com/hbollon/Urbalog
All Nearby stuff is in NetworkHelper class and permissions list is in the constant REQUIRED_PERMISSIONS inside it.
Someone would have any idea?
Thanks in advance

So I have found the issue, on my android 10 devices I haven't activate location and Nearby seems unable to activate it itself...
I never notice that before Android 10 update so is it os related or have I always activated it before? I don't know ^^
However, on the ConnectionsStatusCodes documentation, MISSING_SETTING_LOCATION_MUST_BE_ON status code is marked as deprecated ( https://developers.google.com/android/reference/com/google/android/gms/nearby/connection/ConnectionsStatusCodes ).
So I imagine this is no longer a possible case no?

Related

Does the Android Network Provider exist on Android Studio Emulators?

I am trying to reverse engineer an app that uses the Android LocationManager. It is attempting to request location updates via the .requestLocationUpdates method. However, I am receiving an error that the network provider doesn't exist:
java.lang.IllegalArgumentException: provider doesn't exist: network
at android.os.Parcel.createException(Parcel.java:2075)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:1151)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:1019)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:558)
This error logged after clicking a button in the app and then it crashed. At the time of executing this action, I was using Genymotion Desktop Emulator running a Samsung Galaxy S10 on Android 11.0 API and x86 architecture. After some research, it seems like the issue is due to the fact that Genymotion does not have a network provider enabled. After even more research, it seems emulators can't use the network provider period.
I'm not an Android expert and all of the links aren't exactly the same as my case, so I'm trying to see if there is still a work around/if the outcomes of these links fully apply to me.
Since my issue seems to be Genymotion related, I have decided to try and use Android Studio's emulator instead. I have created a virtual device via the Android Virtual Device Manager (AVD). It is a Nexus 5 API 30 using Android 11.0 (Google Play) on x86 architecture. It is my understanding that there are three location providers in android and the one that I need is the network provider.
My main question is: Do Android Studio Emulators have the network provider enabled?
If not, is it even possible for an emulator to have it enabled or should I consider purchasing a real android phone for this case?
You may be asking why I don't just try to click the same button and see if the error replicates. Well, I simply can't right now. The reason is quite complex, but in short, the button only shows up occasionally for me to press. I don't know when it will be available again, so in the meantime I'm trying to prepare my setup and gain a better understanding of android's location manager.

Android Peripheral BluetoothGattServerCallback onServiceAdded() not getting called

So I have a simple Peripheral application that I am coding in Android Studio running on my Samsung S8 mobile phone. I can setup all my BLE Advertisements and Characteristics just fine but when I add my services. I am not seeing expected results when connected from a another Central device (ie. another mobile phone that has an app to discover bluetooth advertisements).
LogCat output from Android Studio:
As per the Log, I can only see 2 default services that are Generic Attribute(1800) and Generic Access (1801) which are the default services for any Gatt server. I feel that I am missing the "onServiceAdded()" callback that is supposed to tell whether the service was indeed added and discoverable.
My code has no errors and the addService() call is successful. My question is why am I not able to get a response back from onServiceAdded()? While other Override functions like onConnectionStateChange() seem to work fine. This seems to be very basic and I looked at tons of examples but cant seem to get this last bit to work. Anyone with a solution or some good references to look at would be greatly appreciated.
I had the same issue (Nokia 6.1) where onServiceAdded was called only once although I was adding 2 services and I was getting randomly
onCharacteristicReadRequest() no char for handle nnn
when trying to connect from another device.
I found a relevant point in the documentation https://developer.android.com/reference/android/bluetooth/BluetoothGattServer.html#addService(android.bluetooth.BluetoothGattService)
The BluetoothGattServerCallback.onServiceAdded(int,
BluetoothGattService) callback will indicate whether this service has
been added successfully. Do not add another service before this
callback.
The reliable solution I found was to add one service, wait for onServiceAdded to be called, then add the second service, wait for onServiceAdded again and then I call startAdvertising.
I had the same issue, and it seems like callback is not called when a client(Center) was previously connected when the GATT server was restarting.
If you disconnect all the clients and restart the server(peripheral) from clean state, you will see the callback working(in my case, even with 2 services added).
My server is Samsung Galaxy S7(Android 8.0) as well. Client was Android 7 devices.
(In addition to this callback issue:)
There is some caching or strange thing going on, and if you had previous connection it does not work well with multiple services(one predefined and one custom). In my case, when a client was already connected and if I add more than 1 service to the server when starting, gattServer.getService(uuid) was returning null. Adding one service was ok.

Android AWS Cognito: unable to resolve host

I am having difficulty getting Cognito registration and login to work for my app in Android Studio using this sample. When I attempt to log in via the simulator, the app works for a few seconds, then displays an error message: "Unable to execute HTTP request: Unable to resolve host 'cognito-idp.us-east-1.amazonaws.com': No address associated with hostname". This same error is the only error that appears in the console. I have seen similar questions and tried solutions such as checking to ensure my app has the permissions android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE, but the error persists. It also doesn't seem to be a network issue. I have updated to the latest version of the Android SDK as well as the AWS SDK, and the problem persists.
I currently I have a Cognito user pool set up which works properly for login on the iOS version of my app. Following the instructions in the readme for the sample code, I added an app to my existing user pool, and then copied and pasted the newly generated app client ID and app client secret into AppHelper.java for clientId and clientSecret respectively. I also set userPoolId to the ID listed for my user pool under "pool details" in the Cognito conosle, and cognitoRegion to US East, since this is the region of my user pool. I noticed that there was no need for me to set the pool name, as there was in the iOS version, so I'm wondering if that's something I need to do.
Sorry if this counts as a duplicate, but I wanted to post a question with the exact error message I encountered and the steps I took, and I'm wondering if someone has managed to get this specific sample working and what I should do.
The problem has been resolved, but unfortunately I'm not quite sure what fixed it since I didn't change anything in the code. All I did was install an update, so anyone with a similar problem should probably ensure that all SDKs used in the sample are properly updated, along with the simulator. It's also worth noting that I was using a different network than in my previous tests, so it's possible that it was a network issue after all.
I had the same issue.
The issue occurred when I used a VPN with emulator to test my program. The reason was that the internet connection in the emulator was too slow when connecting through a VPN.
This could also happen if your internet connection is not strong enough.
The solution is, use a real android device to test your code, if your internet connection is not good enough.
More info: https://github.com/aws-amplify/aws-sdk-android/issues/567

Fast connection to Google Services ( in order to receive push notifications)

I'm facing an issue on my phone under Android Jelly Bean 4.2.1 (but not on my tablet with Android KitKat 4.4.2).
What I have is an instant push notifications system which works perfectly, as long as my phone is connected to Google Services (blue icon in the notification bar on Jelly Bean). I'm working with Parse.
The problem is that it takes about 2 minutes to get a connection and that is way too long.
I've seen a lot of threads about the Heartbeat rate and tried to add those lines in my code:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
but it did nothing and I don't think that it is really my problem here.
In addition, I found by dialing *#*#426#*#* that it was possible to get a connection in less than 5 seconds by clicking the "Connect" button in the Google Play Services monitor.
My question is: How can I have a fast connection with Google Services (blue icon) in order to receive instant push notifications and is this still a problem on Android KitKat and Lollipop?
I Hope you will be able to help me.

Android c2dm push notifications after app reinstall

I have the following question:
I've successfully implemented C2DM in my application. I'm registering to both google c2dm cloud and a custom server that "creates" notification contents. Everything is working fine.
My question is : what happens when i uninstall my app and then reinstall it on the same device? I've noticed that C2DM is sending me back the same app_key, so apparently there's no way to determine my app installation status change. And i keep on receiving old push notification (they're customized by user preferences in the app).
I won't be able to test with a google play published app until final release, so i would like to know if there's a chance that google itself could notify c2dm that the app was uninstalled on my device and force it to change my app_id at next restart.
Thanks in advance
Stefano
From what I understand in C2DM, you shouldn't depend on Google's registration ID by itself. They "promise" nothing - you might even get a new registration ID without a clear reason (might be their own vrsion upgrades, etc.).
If you want to follow installation - you should do it with your own server - create a unique identifier whenever the app asks for registration, and use it and not the Google's registration ID.
Regarding to Google Play - couldn't find a difference between published app and unpublished one - the behavior seems to be the same.
Hope this helps somehow.
Shushu

Categories