I'm trying to discover Chromecast device on my network, select it and use for video streaming in a newly launched activity. It all works fine until I exit my "streaming" activity and return to "discovery" activity. I start a new discovery upon return to this activity and this time it is not finding my device (onRouteAdded() never called).
I call mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
in onResume() and mMediaRouter.removeCallback(mMediaRouterCallback); in onPause().
Is there anything else I need to do to restart discovery process? Note that I don't use MediaCast button and handle RouteAdded/Removed and selection manually.
Thanks.
Related
I am developing a custom dailer App incoming call screen but my problem is that when the app is in foreground, on incoming call the broadcast receiver is called and displays the custom screen but when the app is in the background or not in running state then the broadcast receiver is not called.
How to resolve this?
And Also Getting this Log
ConnectionTracker: Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lt#3e5af9d
On some devices (notably low-end and Chinese manufacture) apps are not permitted to perform background activities if they are not in a list of "protected apps". This is done to save battery life. If your device does this, it will not launch a BroadcastReceiver if the app is not already running. To fix this you will need to manually add your app to the list of "protected apps" or "apps allowed to perform background activities". There is a setting in the Android settings for the user to maintain this list of apps. It is usually in the "Security" or "Power management" settings somewhere.
I am working on an Android fall detection application. When user falls, alarm with timer turns on and if user not clik cancel within 15s, app send SMS to contact. Everything works fine when app is open but I don't know how my foreground service should work. Is it possible to make foreground service work like that- after fall detected foreground service open application and run timer from Main Activity?
Code from foreground service opening MainActivity:
Intent myIntent= new Intent(this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
There are two obstacles to your use case:
Firstly, starting from Android 10, there are new restrictions on starting an activity when your app is in the background (and as it's written on the android developer page, even with a foreground service, your app will be considered in the background if no activities are in foreground). So you won't be able to "pop" a view to the user, except if you target a version < 29 (but it's not very recommended).
Secondly, since the beginning of 2019, the Google Play Developer Policy has been updated and you cannot use anymore the SEND_SMS permission, unless if you can justify in the publish console that your app is an SMS handler and you will need the user to register it as the default one. So you won't be able to send an automatic text message directly.
You can try to change the notification message to alert the user and try to have him click on the notification to open an activity.
I am trying to create an app that will keep my device wake until I tell it to turn off via code. I can use the follow code in a application...
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
That will work until I tap on the home soft button and then the flags will clear. So, I thought of putting that code in a foreground notification service and broadcast receiver for my action buttons. I can't getWindow in a service or broadcast receiver classes unfortunately. Is there an easy way to get around this?
My goal is to setFlags to keep the screen on from the Activity, and then the service takes over from there so I can close the app, and the keep on screen stays on until the service is turned off.
Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android
I am using Google Voice in my android app, and I am connected the app to Bluetooth module, each time I call the Google Voice, the app try to connect to Bluetooth again, each time Google voice window Popped up, the connection lost, and once the window disappear, and the connection comes back again. So, Is there any way to keep them connected even I call the Google Voice window? Any ideas or help I will be appreciated.
You need to create background service for your problem. If you need persistent connection with your Bluetooth you can use intent service. If you are using android studio then it is very easy to create service. Just make sure you must have all necessary information about services and how to make then persistent in background.
Because of this your application will drain your device battery drastically. Make sure service is closed when application exit or all activities are finished.
See this link for more information
https://developer.android.com/training/run-background-service/create-service.html
Place the Bluetooth related processing in a Service. Make the service foreground service.
Activity can connect/disconnect from service anytime.