Multiple apps connect to bluetooth issue - android

I have 2 applications w/ the bluetooth code derived from the Bluetooth Chat sample. Individually they work fine. Each app connects via SPP to separate devices. The issue I'm having is on phones with Android 2.1, after the first app connects to its device, you can press Home and get to running the other app, but as soon as the connection is made to the other device with this other app, both apps get the "Sorry! The application xyz (process com.xyz) has stopped unexpectedly. FORCE CLOSE" dialogs. There are try/catch blocks throughout the bt code, for which the catches are not executed. Neither app will then connect (individually) until after bluetooth is turned off then on again. This does NOT happen when these same apps are running on a Samsung tab with Android 2.2 - both apps can run and connect to the devices simultaneously just fine and you can switch between the apps, no problems.
Is this specifically an Android 2.1 issue or something else? Whether it is or not, I need some way to prevent the app from connecting if another app is using bluetooth. I couldn't find anything in the Android APIs that would allow finding this out. Is there any way to coordinate/manage this? Does anyone have any specific insights into this whole issue?

I think it is a bug in the samsung bluetooth stack.
upgrading the my samsung to cyanogenmod fixes it.
see this link
http://www.samsunggalaxysforum.com/firmware-problems/connection-problems-sgs-bluetooth-spp-device/

Related

AntiVirus kills my application

I am working on an Android application that uses Bluetooth to communicate with a nearby PC.
The app works greatly on my own device (Samsung Galaxy Note 3 - CM 12.1) but on of my beta-testers it does not.
Simply put the app allows people to write and receive SMS from their
PC (with my C# WPF app) via Bluetooth & their phone.
My beta-tester is using a Samsung Galaxy Note 4 stock ROM (Lollipop).
At first I thought when his screens turned off, Android would kill the MainActivity which holds on a few threads including the one maintaining the connection alive (with a inpustream.read() blocking method). Such behavior does not occur on my own device : I could keep the connection alive for a whole night without plugging my phone.
I was warned, though, that using services would avoid such problem because Android does not behave the same way from one device to another. So I updated my app and made my MainActivity use my MainService to spawn the relative threads. But it did not change a thing.
As my title suggests, the problem lies with his antivirus and more precisely : AVG.
I have no knowledge on how such antivirus work on Android and I don't even use one. By freezing AVG with Titanium Backup on his rooted Galaxy Note 4, my app stopepd crashing and is now working perfectly well as intended.
So I wonder, how come AVG deciced to kill my app when the device screen turned off?
How should my app behave so that this won't happen with any other users using AVG or any other antivirus ? What should I do so that my app does not look as a suspect ?
I don't know exactly what the AVG did to your app.But I think that AVG may don't let your app force to turn on the bluetooth or use the Bluetooth when Android device is sleep or send/receive SMS.The AVG is one kind of antivirus apps that most of them have lots of permission request limited or power saving strategy,especially on rooted Android devices or the first part app already in the Android ROMs.
Try to make clear that what's the real point AVG did to your app.And then try to solve your problems with gentle and smart.
For example:
1.If the AVG doesn't let you use BluetoothAdapter.enable() to force to turn on the Bluetooth, try to use Activity.startActivityForResult() to let users to choose whether turn on Bleutooth or not.
2.If the AVG doesn't let you use Bluetooth when the Android device is sleep.You can try to use WakeLock.acquire() to hold the Android device.
3.If the AVG doesn't let you use SMS sending or receiving.You can changed another communication protocol, SPP or BLE or something else.
Maybe you have heard Xiaomi.If you are an Android Developer in China,because Xiaomi is very popular in China,you must deal with the adaption with Xiaomi,and then you will find that Xiaomi is really fucking for Android Developers in China.
Xiaomi doesn't some really amazing things to the original Android.For example:
1.
AlertDialog..getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
you can't alert the TYPE_SYSTEM_ALERT dialog on some xiaomi ROMs that they tell you nothing.
2.Xiaomi has modified lots of original themes.
3.Xiaomi has changed the Android alarm timing mechanism while the device is sleep which is called Wake-Up-Alignment.This is really terrible for the apps that with the function of timing.
The above problems are that I met in Android development, some problems I can resolve it, some you don't have any chances to change it.
Remember that:The adaption with Android devices is that you must make your users know you app works on most of the popular Android Devices,the developers try to make the app run on most Android devices,but it maybe not work on some Android devivces with customized ROMs or with some special third part apps.That's it ,that's true, that's Android.
If the problem can't be solved,it's not a problem!

Chromecast API doesn't accuratelly detect when device is connected/disconnected

I have a problem when i am trying to use my chromecast device.
Currently I have an app for Android , one for iOS
and these 2 apps from github.
https://github.com/googlecast/MediaRouter-Cast-Button-android
https://github.com/googlecast/CastVideos-android
All of them have a common problem. They sometimes cannot accuratelly tell if a chromecast device is connected or disconnected.Taking around a minute before they find it out themselfs.While an application like Youtube , discovers if it is connected or not, instantly.
EDIT #1 START:
While using the application "Cast Videos" for android from GitHub the following thing happens.
I hold the android device in my hand (Samsung Galaxy S2).
I know chromecast is on because I can see it on my monitor.
I start the application "Cast Videos".
The Chromecast icon does not appear, even if the chromecast device is on.
EDIT #1 END;
I have tried using the app_id from my own receiver application , and the default receiver app_id.
I have found a way to trick them into finding the device. By launching the youtube application on an Android or iOS device , connect to the chromecast device , then disconnect.
When I return to on off the apps I have mentioned at the start of the question , they can detect it now , and connect to it.
The two applications from github are not modified , and use the most up to date support libraries (appcompat, mediarouter, CCL).
The applications are now being currently build on a Mac (if that matters). I don't think it will be of any difference if they were built on Windows or something else.
EDIT #2:
I am starting to suspect that actually the wifi router in the building im programming may cause these connection problems. Because when I send the app to other people they don't have the same problem.
EDIT #3:
Good news :D.
The latest update on the castcompanionlibrary made chromecast detection much more reliable and the sample now detects preciselly every time if it is connected or not.

Detecting iPhone using Android Bluetooth without discovery activated

I am trying to detect my iPhone on my Android 1.6 device using Bluetooth without interaction.
I can do it when the iPhone is discoverable, meaning I have to interact with the iPhone, going through menus to Bluetooth section.
For what I have searched so far, it's seem impossible to detect the iPhone, even if it has been previously paired (paired is only a kind of shortcut to avoid the heavy discovery process).
Does anyone know any solution ?
Thanks
Antoine
In my experience, if the iPhone goes out of range or otherwise disconnects a BT connection, there is no automatic reconnect, you have to go in to the BT menu in the iPhone.
I have not worked on iPhone vs android on this, but I know a lot of the car stereo and gps manufacturers are having problems with the iPhone not reconnecting automatically.
At the moment they don't have a solution, so I doubt there is one.
Short edit for clarification: This is not an android problem, I work on BT certification and licensing, and android can drop a connection and reconnect automatically. (Under the condition that the phone supports that BP profile, but they all do.)

Problem in Pairing the Android device with other Device through Bluetooth

I have a problem in pairing the android Device (Desire) with any other Device (e.g Nokia) through Bluetooth, and i am using the Application the (Bluetooth-Chat) provided in the samples of the SDK 2.2, the behavior of the Application is that it shows all the devices having bluetooth switched on, and also paired it but only android devices, so how can i connect the android device with any other device (e.g Nokia), what are the limitations, what needs to be change in the Code, i tried to debug the Code and find out where the problem exists but i do not found any reason.
So kindly help me in this regard, i will be very thankful to you.

Android Multiple SPP / RFCOMM Connections Causes Massive Slow Downs

I have an app that uses bluetooth SPP (RFCOMM) to communicate with a piece of hardware. The app and the bluetooth connection work great. The problem is when another app is started that also uses SPP and then one of the apps is stopped. Once either of the apps is stopped, either by quitting the app or by using a task killer, the phone slows down to a near halt. Most of the time I have to pull the battery.
I have seen this with Pandora, which uses SPP, probably as part of its Ford Sync support, and with my app. I have also seen this with the sample apps for SPP. It doesn't matter which apps I use. Any two apps that use SPP cause this.
I have seen this on Android 2.1, HTC device on ATT. I did not see this on a Motorola Droid running 2.2.1 stock, however I did see this on the same phone while running 2.2 and LFY 1.95 ROM with a custom kernel.
I have logs from the debugger if anyone needs to see them, but I see nothing in there that points out the problem. Once either SPP apps is stopped the slow down starts immediately. I still get logs but nothing at all indicating a problem. The slow down does not stop until the phone is rebooted.
OK I'm just going to blame this problem on HTC. Seems like HTC devices running Android 2.1 have a very buggy Bluetooth stack. There are lots of complaints on HTC's forums about bluetooth issues.
I was able t work around this by closing my SPP connection when my app is pushed to the background then restarting the SPP connection when my app comes back up.
I don't want to do this because a future version of my app will need a SPP connection even when the app is in the background. I just hope HTC fixes their buggy software before I implement this.
If anyone has more info on HTC's buggy bluetooth stack and the inability for HTC devices to handle more than 1 SPP connection please post.

Categories

Resources