I'm building an app on an android Professional device (not a smartphone or a mobile). I have a problem that drives me crazy..
I've registered my receiver only once. I destroy it when the activity is destroy.
To be sure, before register for it, I've wrapped an "unregisterReceiver" in a "Try and Catch".
But, unfortunately, My intent is sent only once (log confirms that) and my receiver receives it twice.
So how to avoid that?
It runs with Android 10.
Related
I have an application on Android devices that listens for incoming calls (incoming call intent) through broadcast receivers and displays a popup on the screen when a call comes in, even when the application is completely closed. This works immediately on the emulator, but on some devices, the popup does not appear until 2-3 minutes after the call comes in or does not appear at all. The problem is that the broadcast receiver is unable to catch the intent. How can I solve this?
I couldn't make a try. because I couldn't find the root cause of the problem.
When pressing the call button in the contacts app, I want to launch my own app to call with. The only method I have found to do this is with a receiver that listens to the NEW_OUTGOING_CALL broadcast. But this is ugly and means that all calls are routed through my receiver.
At the moment I have registered multiple intent-filters on the DIAL, CALL and CALL_BUTTON intents, but none fire... I am testing on a Samsung Galaxy S7 with Android 7.
As you wrote: When pressing the call button in the contacts app, I want to launch my own app. . . . then But this is ugly and means that all calls are routed through my receiver, both parts are in contrast.
The best way (and I think the only one since contact app is not "yours", it's owned to OS), is as you did, with a receiver.
What I can suggest to you is to add a custom filter(programmatically) within your onReceive method and to ask when it get awake to ask if the contact is the requested and then open your app via Intent.
I believe that using a Broadcast receiver is actually the recommended way of doing this. It's not possible to actually change the calling application; that's pretty much bound to the OS. Even with a rooted device, you'd have issues.
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.
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.
I have an app on Android that reacts to incoming calls.
Now, since the OS shuts my app down whenever it want,
I need a way to to listen to the incoming calls and launch the app when it happens.
Will a BroadcastReceiver help? (just like launching on device restart)
Any idea?
thanks!
I think you have answered your own question. This is just the sort of thing a broadcast receiver is meant for. If the receiver is registered in your manifest then the application does not have to be running.
It will be automatically started when a matching intent is broadcast. Typically the response will be to update content or activities, make notifications with the Notification manager or launch/manipulate services.
Note that there is a 5 second execution limit in the BroadcastReceiver onReceive handler to ensure you do not try to do any 'heavy lifting' in it. Exceed this and a force close dialog will be displayed.
Yes a BroadcastReceiver would to the job as it will fire even you app is not running.