I'm using the Android notification system.
This system save an id for all devices for which notification will be sent.
When any user uninstall the APP and the attempts to send one notification throws an error.
Can I code any method when the user unistall the app? Android has a method that runs on the app when it is uninstalled?
No. your app will not get any notification while being uninstalled. There's ACTION_PACKAGE_REMOVED broadcast, but your app will not get it as it is being broadcasted once the package is removed, so your app is already gone at that time. Docs read (here):
Broadcast Action: An existing application package has been removed
from the device. The data contains the name of the package. The
package that is being installed does not receive this Intent.
There is no way for an app to tell if it has been uninstalled or to receive notification of it's pending uninstallation.
When an application is removed, the ACTION_PACKAGE_REMOVED intent will be sent out to all receivers except for your own. Read the docs for more.
There is no callback that you will get when your app get uninstalled.
while an app is uninstalled ACTION_PACKAGE_REMOVED intent will be sent to all receivers except the currently uninstalled app so by another app you can know that.
Your code is inside your app, not outside to send any notification at a time of uninstalling it.
Outsider coding is done by Android OS so leave it to him.
Related
I want to trigger the logout process for the user in case the user uninstalls my app.
This way I want to ensure that I reach the user via other means like SMS / email instead of sending app Notification.
Is it possible to run some code just before uninstallation of my Android App ?
Is it possible to run some code just before uninstallation of my Android App?
No. You can get the broadcast for any other package getting uninstalled but never for your own package.
But you can observe other packages being removed by registering for this event.
android.intent.action.PACKAGE_REMOVED
WE have Android application in the play store, we would like to send communication to all uninstalled app users, is there any way we come to know who are the users who have uninstalled. kindly help
ACTION_PACKAGE_REMOVED is the Broadcast Auction that informs removal of application but you can't receive it on that Application which is removed. Yes if you have other application of you on same device, you can do whatever you want "Like sending that event to server" on removal of any application package!
Broadcast Action: An existing application package has been removed
from the device. The data contains the name of the package. The
package that is being removed does not receive this Intent.
There is an other way that give functionality of uninstall in your application and track the event. App can be uninstall this way!
//Uninstall event you can send to server before start activity
Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(intent);
There is another way that is get root Access in your Application for that purpose this link may help you after becoming the SU you can do lot of things that you cant do normally!
I am testing the sample project for gcm notification from google
https://developers.google.com/cloud-messaging/android/start
This project is using com.google.android.gms:play-services-gcm:9.0.0
After I install the app to my phone via android studio.
I kill the app from my phone(not force kill from setting).
Then, I tried to send notification message according to google instruction.
Notification cannot show on my phone. When I check the logcat. I found the following log about GCM.
06-08 11:19:37.859 5080-5080/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=gcm.play.android.samples.com.gcmquickstart (has extras) }
After that I launch the app in phone and kill the app again, then send GCM again to my phone. At that time, notification can show correctly in my phone.
It seem, application need to restart one time for receiving gcm notification or application should be received notification before user kill the app.
How should I solve this problem?
As I know, lower version of play-services-gcm:9.0.0 do not have this kind of problem.
It's a feature of the Android platform. Force stopping an application by the user puts the application in a stopped state and none of its code is run, including any broadcast receivers declared in manifest. Only when the user explicitly launches the app it is put in a state where the receivers get fired.
Read this thread
EDIT: It maybe that you gym token doesn't have time to register with the server. Do you get a token and a registration confirmation from the server?
If your just starting with GCM then I would suggest to use FCM it is replacing GCM.
https://firebase.google.com/docs/cloud-messaging/
Same thing but with support and new examples. It looks even easier to use than GCM.
When I installed the app by using apk file, this problem is not happen. This problem is only happen when I install the app by running project in android studio. Thanks for all suggestion and answer.
Best fix I have so far is to unplug the phone, kill the app, restart the app then kill it again. Doing this will have the notification displayed even after installing it via android studio.
Here is another thread regarding the issue: https://code.google.com/p/android/issues/detail?id=219084
I want to register gcm_id imidiatly after app was install or updated (as gcm_id may change over application or android id) to be able to send user news asap.
I can listen for broadcast android.intent.action.MY_PACKAGE_REPLACED if my package is updated. However broadcast for android.intent.action.PACKAGE_INSTALL is deprecated and does not seems to work (have not seen logs with such intent) and broadcast for android.intent.action.PACKAGE_ADDED is never send to newly installed application as stated in docs.
Is there a work around to listen, when my app is installed?
Is there a work around to listen, when my app is installed?
No. Nothing of your app will get control until the user clicks on the launcher icon for one of your activities, or until something else uses an explicit Intent to start up one of your components.
Please register for GCM on the first run of your app.
When none of the activity is launched even once,i want to send a push notification to the user.
For example, once user installs application but doesnt open then a notification is pushed that please use the application.
Please help me with the code.
You can't. How would the user call the registration process for the push messages if he never ran the app itself? Until he does, the app is considered to be in a stopped state and you can't interact with it unless you have another app installed that would "start" it.
You can start a background service on application level and registering on gcm server and other process so even if app is not used you can send notification as your service has registered your device with gcm id on your server.Call api for registering device to your server from your GCMIntentService class.