I have an app that is started on bootup via manifest entries:
<receiver android:enabled="true" android:name="com.vwp.owmini.BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<action android:name="android.intent.action.BOOT_COMPLETED" />
This app itself starts - dependent on configuration - a foreground service and brings own Activity to background. This works well and without problems.
But: when the app is updated because a new version is available in Playstore, it is stopped but not restarted afterwards.
So: how can I tell Android to restart this app after an (automated) update from Playstore?
Thanks
From another SO-question
Register a BroadcastReceiver to Intent.ACTION_PACKAGE_REPLACED
Then, compare EXTRA_UID with your own. If it matches, you can start
your service again.
Related
I have developed an Android health app which launches a process running in the background and monitoring user activities such as steps. If the app is closed by the user, the core sensors monitor keeps running in the background.
I am about to upload a new version of the app to the marketplace. What will happen to the background service when the app is updated? Will it be killed?
Tests on the beta channel seem to indicate that the background process is somehow left in a semi-dead status (i.e. the process is there but is not working).
Shall I make sure that the background process stops when a new version is installed? If so, how?
Thanks
While updating to new version, the app is killed by Android. It means that Android stops all the background services as well, but once the app update is done, then the services are restarted.
All the processes are killed. If you want them to be restarted you have to set an intent filter with android.intent.action.MY_PACKAGE_REPLACED on the background processes. For example in my Manifest file I have created a receiver that has the following:
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
This will guarantee that this receiver (which will restart the services) will restart after reboot and after package reinstall
i created an android application with no activity. I want to start a service using a system intent like BOOT_COMPLETED. I use the following receiver:
<receiver android:name=".autostart" >
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
I got the problem, that the intent is not received when power is connected/disconnect or boot completed. Is an Application with no Activity even in stopped mode after install? How can I start the service? UI is not possible because the application has no activity...
Is an Application with no Activity even in stopped mode after install?
Yes.
UI is not possible because the applicatio has no activity...
Then add one. You need one anyway, to present your license agreement, your online help, your configuration for this background processing, and so forth. And, since your app will not run until the user launches this activity, you need to for that reason as well.
Every Android application needs to be launched at least once after installation and only then it will receive any intents from system. This means an application without any gui will not work in your case.
Many applications include only "about" activity, which is a common way to deal with that.
Please see:
http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
I have implemented an app that is basically a custom app store for updating and launching a family of related apps. It also needs to update itself, which works, but the app is killed without warning during the install process. I want to automatically restart the app in this case so that the user can continue to use it immediately after an update.
So I made a separate application including only a single Broadcast Receiver that listens for package events for the first app's package name and starts a new activity. That receiver is never called:
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<receiver android:name=".AppUpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
In searching for similar implementations I have seen directly contradictory information on whether an application with only a receiver will ever execute, and whether a receiver will be called if its app is not already running. I've even come across example code of an application containing only a receiver, with a manifest very similar to my own. So what do I need in this application to ensure that the receiver is called whenever another package is installed?
If there is a better solution, I'd be happy to hear it.
Depending on the version of Android, you might need to start an application component in order for the BroadcastReceiver to be registered. By this I mean there will need to be a launcher Activity which must be started manually by the user.
From Honeycomb (I think) onwards it isn't possible to have application components 'active' unless the app has been manually started in some way. The reasoning behind this is the potential for insecure code executing without the end-users' knowledge.
I suspect this is what you're experiencing. To test it, add a simple "Hello World" Activity to the app that has the BroadcastReceiver in it. Launch the Activity and then check to see if the BroadcastReceiver then gets called after your other package is updated.
I've recently added GCM messaging to my app using google's helper classes (GCMBroadcastReceiver, GCMBaseIntentService). It works beautifully when the app is running, both when it's in the foreground and when it's not. However, when it's not running, nothing works.
As a test, I extended GCMBroadcastReceiver and added log statements to getGCMIntentServiceClassName() and peekService(). When the app is running and a message arrives I see the former called. The OS then instantiates my service class, which eventually results in onMessage() being called.
When the app isn't running getGCMIntentServiceClassName() never gets called.
My manifest is pretty much the boiler-plate code from Google's GCM examples.
Is there an extra permission or flag I need to set in order for the OS to wake up my app when it's not running and a message arrives w/ the correct intent category? My receiver is defined as:
<receiver
android:name=".GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="PACKAGENAME" />
</intent-filter>
</receiver>
Bear in mind: this works when the app is running in the background.
Bleh. Figured it out. David Wasser's answer here:
BroadcastReceiver isn't working
explains why I'm not seeing the broadcasts when my app isn't running. I was force quitting it from Manage Applications, which puts it into the "stopped" state (and thereby causes the system to exclude it from broadcasts by default).
When I install the app, launch it, power down the device, then power it on again, I'm receiving the broadcasts properly.
I had same issue and fixed by just running the through RUN button from Android Studio.
I think in Debug Mode it doesn't work
Is there a way to detect from app code when it is being reinstalled.
I saw that app update from market can be detected by listening to PACKAGE_REPLACED event in broadcast receiver. But that these events are not delivered to the app , if the app is reinstalled from editor (eclipse ).
My requirement is that i am disabling a component(Launcher activity). The app install will fail if it is not enabled. SO everytime before reinstall i want to enable this component.
I am talking about the reinstall before publishing in market. While developing , each time i reinstall the app to test some modification, i want to detect this from my app and make the component enabled.
I saw from my example that the following events will be broadcasted when an app is reinstalled from eclipse.
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
</intent-filter>
I defined a broadcast receiver for these actions and from onreceive i am able to enable my component