Bluetooth discoverable with Android-TV - android

I developed an app using Bluetooth in android that works fine, but I encounter some issue when I try it in Android TV.
According to Bluetooth tutorial, I used this to make my device discoverable:
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
It works fine in normal device, but in Android TV, I get an ActivityNotFoundException:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE (has extras) }
If I understand well, this exception means that there isn't an activity by default to ask the request to the user (I think the default dialog to ask the permission).
So is there a way to create our own kind of activity (to handle this behavior) or may be not ask the permission to the user. Or of course, may be my approach is totally wrong.
I don't know if it's useful but I'm developing on the Nvidia SHIELD TV.

This is probably related to an issue in your manifest. You'll need to declare one of the Activities in your app to have the capability to receive an Intent from
act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
Check out this this answer for more information about how to declare Activities in your manifest.

There are some problems with the ANDROID 6.0 MARSHMALLOW and bluetooth. I had a similar problem : I could'nt perform a discovery with my app on the Android TV but it worked fine with my phone(and I had no Exeptions). I drop the ANDROID 6.0 MARSHMALLOW and went to the 5.3 and it works after that.

Related

Android Wear is not opening dial pad via intent

I am working on an android wear project, I am facing an issue while opening the dialing activity via intent. The problem is that Intent is opening the call history instead of the dial pad.
Code snippet
val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:0526722293")
context.startActivity(callIntent)
I have checked different stack-overflow post but still facing the same issue.
Can we make calls to any number in Android Wear 2.0?
How to make a phone call using intent in Android wear?
Is there anything that, I have to do more for android wear
If you are testing the app one an emulator, try the same on a physical watch. If the issue still persists, you might want to check the following:
Do the app have required permissions
Is this specific to a device/OS version
Ref:
https://developer.android.com/guide/topics/connectivity/telecom/selfManaged#constraints
https://developer.android.com/wear/releases?hl=ko

Why the service doesn't start

I'm starting to develop for android, and I'm having an issue about services. I did a lot of research about this, but couldn't find a solution.
I'm doing an app that collects RFID tags information. For that, I'm using a third-party middleware that handles the bluetooth connection to the RFID reader and other events (like connecting, reading, errors etc). So, my app creates a broadcast receiver that handles all the message and data intents sent by the middleware. For this part, everything's fine.
The problem is that I'm trying to start middleware service using the code below (provided by the middleware documentation), but it doesn't work.
Intent intent = new Intent("com.supplier.middleware.runner");
intent.setPackage("com.supplier.middleware");
startService(intent);
I'm currently using an Asus Zenfone MAX M1 (ASUS_X00HD) with Android 8.1.0. The documentation also describes a way to stop the service (which I must use when I close the app), and the stop service intent works. So, if I start the middleware manually and try to close programatically, it works fine.
After some days trying - unsuccessfully - to solve this, I tested my app with a Motorola Moto Maxx (which is Android 6, I think) and with a Samsung J1 (which is Android 5.1.1) and both smartphones worked fine: when I call the startService, a notification item appears; when I call stopService, the notification item goes away.
I also tried to use "startForegroundService" because of the Android 8, but no success either.
Is there a way to "monitor" the startService calls, so maybe I could track any error? Am I doing something wrong - or rather, am I not doing something that is important?
In Android 8.0 background service limitation.
https://developer.android.com/about/versions/oreo/background.html
You can use JobIntentService instead of intent service. It can work.

Notifications won't push to real device

I was following along to TheNewBoston Android App Development for Beginners - 63 - Styles video for pushing notifications.
The app works perfectly in Android Studio's emulator, but when I run the app on my phone, the notifications won't show up.
Is there a reason notifications work on the emulator, but not an actual device?
in some devices like Huawei you need to make your app as protected app to use notification feature. you can use below code to detect Device Model and make decision to go to the protected app setting.
String PhoneModel = android.os.Build.MANUFACTURER;
if ("huawei".equalsIgnoreCase(PhoneModel)) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
}
Shortly after I posted the question I figured out what the problem was. I updated my phone to Oreo recently and was trying to use the old way (the way thenewboston did it inside his videos). Apparently for android Oreo you have to code notifications with channels, the old way for notifications is not compatible with Oreo.

How to get know when application's background services got block by other super-access application in android

My application performs data synchronization in background service which is critical task for application in order to work properly. now, application works fine & expected in some of devices having pure Android or near to pure Android ROM. e.g. Google Nexus, Android One & Motorola devices. but, some devices like Redmi having MIUI has inbuilt options for blocking application's background processes. which causes my application working not properly. So, I want to know "is there any way to find out my background processes are blocked? so that I can notify user to unblock it."
here's a somewhat related question
here's some screenshot related to this.
Any suggestions or help are welcome.
Thanks in advance
as i know, apps cannot get the info about whether or not in whitelist, but you can notify the user any more by :
Intent intent = new Intent(); intent.setAction("miui.intent.action.OP_AUTO_START"); intent.addCategory(Intent.CATEGORY_DEFAULT);

Android bluetooth permission denial (although I use permissions)

To cut the story short. My logcat says:
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
cmp=com.android.settings/.bluetooth.RequestPermissionActivity (has
extras) }
While I'm trying to execute:
Intent discoverIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 600);
startActivity(discoverIntent);
I have included all required permissions in the manifest. Moreover, some time ago I have written another application using bluetooth, which includes exactly this code (and I'm using the same there permissions). In that app everything works properly, here I get this exception while executing startingActivity(discoverIntent).
Do you have any ideas what's going on?
ANSWER ANSWER ANSWER
Maybe it sounds silly, but after restarting(sic!) my mobile phone, everything works perfect and I don't get any exceptions. If you have problem like this, try this simple solution.

Categories

Resources