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.
Related
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'm guessing this is a really rookie question, so I'm hoping someone can steer me in the right direction quickly & easily.
I have an app that receives GCM messages. The code that contains the GcmListenerService-derived class is located within my app. Because of this, the user MUST run my app after starting their phone in order for my listener to start listening (verified by restarting my phone, sending a test from Postman, and NOT getting the message / notification until I launch my app).
Do I need to create some type of service or something that will allow my app to get new GCM messages, even after restarting the phone (and not launching the app)?
Thanks!
Yes. You will need a broadcast receiver which listens on the BOOT_COMPLETED broadcast message and launches the push notification service. However, you still have to start the app once to register the receiver. It will also not work if the user force quit the app. There are some approaches, which also will restart the app automatically if the user killed the app, but I think it is a bad practice. In some circumstances the user wants to stop the app and keep it closed.
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.
I developed an app that receives the boot completed intent. From my tests I concluded that I must open the app at least once to start receiveing this intent.
Is this the correct behavior? If so, is there any way to start receiveing intents without starting my app at least once?
Thanks,
-George
The app must be opened before any code can be triggered, there is no way around this.
Hi I am working with android.Firstly I am not familiar with broadcast receiver. I need to create an app in which, if anyone installed my app a broadcast receiver will run which check the installation status like ACTION_PACKAGE_INSTALL and android.intent.action.PACKAGE_REMOVED
.But How can i get these status even my app is closed ?? Is it possible with broadcast receiver ?? Please help me, thanks in advance :)
basically, BroadcastReceiver can receives broadcasts even if your app is not in foreground, or even if your application's process is not alive.
this can be done by declaring the receiver within your application's Manifest.xml file
when you declare a receiver in the Manifest file - then the system would wake up your application and invoke your receiver if it set with the appropriate intent filter that responding to the broadcast that been sent (in your case - ACTION_PACKAGE_INSTALL and PACKAGE_REMOVED actions..)
but unfortunately there are also bad news for you:
from Android ICS and above - you cannot receive any broadcasts until you application launched explicitly by the user at least once!
this is due to security reasons Google decided is necessary, to prevent from malicious apps doing staff entirely transparent without the user launched them at all even once..
so the answer basically is - no! you can't perform any code and receive any events from your app until it launched at least once.
by the way - you wouldn't received ACTION_PACKAGE_INSTALL and PACKAGE_REMOVED broadcasts for your own app that been installed or uninstalled anyway.
by reading your question again, honestly I'm not sure what is that you expects to happend:
it is no make any sense to "check your application installed status" if it unistalled or not. after all - if it uninstalled - then it can't run (and perform any code) anyway.