SessionManager.endCurrentSession(false) stops casting - android

I am using SessionManager to manage a Cast session to a Chromecast device. In my Activity onPause() I have the following code:
val sessionManager = castContext.sessionManager
sessionManager.removeSessionManagerListener(castSessionManagerListener, CastSession::class.java)
sessionManager.endCurrentSession(false)
I found out that the receiver applications stops. I checked the documentation and it says:
public void endCurrentSession (boolean stopCasting)
Ends the current session.
stopCasting Should the receiver application be stopped when ending the current Session.
Even though I use false it still stops the receiver application. Why? I want the receiver application to keep streaming even if my application is in background or closed completely. For example, the YouTube app works that way.

Related

Why Android foreground service stops when I manually disable the location in Andriod settings?

I have written a foreground service in my app and I am doing some API operation every 5 minutes once. My app is mainly used for location tracking and it always needs location permission. If user disable the location for my app by any chance then I just want to create a local notification from my service. My app users mostly don't bring my app to foreground. So I want to check whether the location permission is enabled or not. If not then I just want to show a notification which tells the user that the app needs location permission. Now I just manually went to android settings and disabled the location permission for my app. I have two services running in my app. Suddenly both stopped working. I just want to know the reason why it stopped? Will it be stopped always until I enable the permission? What can I do to intimate my user to enable the permission? As my app always runs in background, I want to handle it in service. Please give your opinion to solve my issue.
NullPointerException: Attempt to read from field'LanguageInitBean$Data LanguageInitBean.data' on a null object reference
When I change the storage permission, I can't read the data stored in memory
Ask for help
public static class LanguageInitCache{
public static LanguageInitBean languageInitBean;
}
private void startToNext(String response) {
languageInitBean = GsonUtils.json2Bean(response, LanguageInitBean.class);
}

How can an apps application class run at once the device starts?

How can an apps application class run at once the device starts?
Hello,
I have an application where the application class is running it's onCreate, but no activites on device startup. And i don't mean when the BOOT broadcast is sent, i mean at once the device is started.
I can see this since i've added file logging to the appliation class, but i cannot see that it comes any further (into any activities).
My manifest has
No receivers
No services with their own process id
Is there anything else that could start my application class on device start?
When i click and start the application on my device, i see logs in the application class again, but this time it has another process id than it had.
Thanks in advance!
===================
ok, so after commenting out all obvious code and manifest entries, i finally set my Sync Adapter Service to enabled=false, and then the problem did not occur. Is this normal behaviour of a sync adapter service?

Android AccessibilityManager getEnabledAccessibilityServiceList returns empty list under certain circumstances

My app extends Android's AccessibilityService to monitor the currently active app. In order to detect changes in activities I have to register my service and get the user to consent to allow the permission. As a convenience to the user I detect whether my service is currently enabled when my app starts, if not enabled e.g. when the app is installed then I redirect the user to the Settings Accessibility page to allow them to enable the service. The following code checks whether my service is currently enabled, the id parameter is the id of my service e.g. com.foo.bar/.MyService syntax:
private boolean isAccessibilityEnabled(String id) {
AccessibilityManager am = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
List<AccessibilityServiceInfo> enabledServices = am.getEnabledAccessibilityServiceList(AccessibilityEvent.TYPES_ALL_MASK);
for (AccessibilityServiceInfo service : enabledServices) {
if (id.equals(service.getId())) {
return true;
}
}
return false;
}
I've seen two scenarios where this check fails even though I know the service is enabled. Firstly if I debug my app from Android Studio this fails and enabledServices is empty, if I run (rather than debug) it works perfectly and returns a single entry in enabledServices. The second scenario I've noticed where it fails is when I run the adb backup command to backup my app, if my app is currently visible when the backup prompt comes up then when the backup completes my app's main activity onCreate is executed and the isAccessibilityEnabled method is checked and again fails to see my service is already enabled.
Is there a special case I need to take into account when calling getEnabledAccessibilityServiceList or is there a reason why my service isn't returned even though when I look in the Accessibility Settings page I can see the service is enabled.
There is an alternative way to query if an accessibility service is enabled, I've used the approach described here - Detect if my accessibility service is enabled and it seems to get around the issues I was encountering.

How to bind with service "com.google.android.music.playback.MusicPlaybackService"?

Is it possible to bind with service "com.google.android.music.playback.MusicPlaybackService"
After searching and trying everything i can think of, i was not able to bind with the service. com.google.android.music.playback.MusicPlaybackService. I followed all the binding option mentioned on page how-can-i-start-the-musicplaybackservice-from-an-external-app,but it throws securityException as mentioned on the page.I checked that the service com.google.android.music.playback.MusicPlaybackService is running on the device.
My requirement is to bind with the service `com.google.android.music.playback.MusicPlaybackService` and control the media playback from another application running in background. Using broadcast Intent i can control the playback as mentioned in the #1 option on the page mentioned above, but using this method i am not able to play a particular song in the default PlayMusic application.

Reboot after install

Is it possible to force a reboot of the device after my apk is installed?
I want to force this because I want to ensure that my service is started.
Most probably the answer is no, your are not allowed to do such things from your app. This is the sole privilege of the user holding the phone (and of maybe the core system services).
You can however ensure you service is started when the user starts you main activity, which would be a very normal thing to do right after the user have installed your application.
For additional information see the question How to start android service on installation, which is in fact what you should be trying to do.
It's not possible in any way to get your application to do anything as soon as it's installed, before the user first launches it from the home screen. There's no broadcast action you can listen for explicitly. However, you can listen for something generic that gets called a lot, such as:
android.intent.action.USER_PRESENT,
android.intent.action.SCREEN_OFF, or
android.intent.action.SCREEN_ON
In any case you should NOT reboot the device. Your users will hunt you down and kill you with stones. Joke aside, Google might actually pull your app from the Market for this. Just listen for one of the actions mentioned above, check if the app has just been installed (using a one-time boolean preference, for example) and start the service.
Note: if you do end up listening for one of the above actions, please disable your receiver the first time it receives an intent. You can do this like so (in your receiver):
public class FirstTimeReceiver extends BroadcastReceiver {
public void onReceive (Context context, Intent intent) {
// start your service (which does stuff asynchronously, of course, and then:
final ComponentName mySelf = new ComponentName(context, FirstTimeReceiver.class);
context.getPackageManager().setComponentEnabledSetting(mySelf, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}
However, you should only do this if somehow this service is absolutely critical for the user (there are few proper scenarios for this), and not for you / your app. As bjarkef mentioned, you should only start it after the user starts your app from the home screen (better yet, ask for permission from the user to run the service).

Categories

Resources