I want to receive Broad Cast receiver for "when will i remove or uninstall my application in device,How to implement,
Thanks
there is no such broadcast. you are not notified when your application is removed
See my answer to [Android] Hook some regular tasks ?.
You can be notified when an app is removed (including your own), but you cannot prevent it or alter the outcome, so depending on what you want to do with the notification, it may not be of any practical use for you.
Also, since your app is being removed asynchronously, your window of opportunity to receive the notification may be too small to do anything practical or respond in any way.
You can use "android.intent.action.PACKAGE_REMOVED" to broadcast the application package that has been removed.
Related
I´d like to control an app with another app.
As far as I know apps in background get paused.
Is there any way to send commands/clicks etc to another app by my control app?
Thanks
Not generally. If you wrote both apps, you are welcome to implement your own control IPC mechanism. An accessibility service can do what you want to a limited extent for arbitrary apps, but nobody with any sense will install your accessibility service, given that you can do all sorts of nasty things to the user and so there are security warnings that get raised when the user goes to activate your accessibility service. On rooted devices, there are probably many more options.
If you want to send click events to another App, you can achieve it by Broadcast Receiver.
You have to send a broadcast message and the other app must have a receiver to receive the trigger.
you can get more information about broadcast receiver by this link https://developer.android.com/guide/components/broadcasts.html
What you are looking for is a service. In a bounded service, Inter process communication is extremely easy, read here.
https://developer.android.com/guide/components/bound-services.html
You simply bound both your apps to a service they can talk to eachother.
I have been trying to do something similar to truecaller app, where my app is supposed to show a screen after a call gets hung up. Was achieving this by registering android.intent.action.PHONE_STATE implicit broadcast in the manifest file.
But it is not working if I change the app to target Android O, because of the Android O broadcast limitation, and I'm trying to figure out an alternative solution to this use case.
Alternative solutions suggested in android docs: Job scheduler or register a service with context.
Job scheduler: Because of the Job scheduler optimizations there will be some delay to receive the callback. So it will affect the user experience if our app screen is shown a few min after the phone call and polling to check for new call logs every few seconds causes battery drain issue.
Register service with context in Java: I want the behavior to work even if the app is not active or alive. This will not work if the system kills the Service.
Register a Foreground Service: This requires a notification to be shown to the user all the time, which would be spam the user, and running a service 24/7 consumes lots of resources which defeats the whole purpose of broadcast limitation.
Please suggest an alternate solution so that the user experience remains the same.
Thanks in advance
Eventually, the action was added to the "Implicit Broadcast Exceptions" list so you can add ACTION_PHONE_STATE_CHANGED to your manifest and it will work:
https://developer.android.com/guide/components/broadcast-exceptions
ACTION_CARRIER_CONFIG_CHANGED,
TelephonyIntents.ACTION_*_SUBSCRIPTION_CHANGED,
"TelephonyIntents.SECRET_CODE_ACTION", ACTION_PHONE_STATE_CHANGED,
ACTION_PHONE_ACCOUNT_REGISTERED, ACTION_PHONE_ACCOUNT_UNREGISTERED
OEM
telephony apps may need to receive these broadcasts.
You have only one solution, use a foreground service and register the broadcast receiver in the service.
As there is NO proper solution to read the PHONE_STATE from Android O. The best alternative we can go for is to trigger a job on new call log entry from the content provider. By this, the behaviour is maintained of showing a screen(with a few sec of delay) after the call ends.
NOTE : The disadvantage is we cannot get the state of the phone call(Ringing or off_the_hook etc.,). The call back will only be received after the new call log has been added to the System DB.
For me, and my production app, the solution would be to avoid targeting api 25 and above, until a better workaround/api comes up.
If your app targets level 24 or below, you're not affected by the new Implicit Broadcast Limitations and your app can still listen to PHONE_STATE broadcasts even when your app is not running.
An app targeting lower APIs can still be downloaded and installed normally on new Android versions, the only reason to update your sdkTarget value is if your app requires usage of new APIs.
There seems to be an broadcast exception for ACTION_NEW_OUTGOING_CALL but not one for incoming call (or when call ends). It seems like a bug to have one for outgoing but not one for incoming. There's been a bug report filed in google issue tracker. Hopefully their answer will clarify what we should be doing.
I'll update this answer if/when the bug tracker gets updated.
As mentioned here: https://issuetracker.google.com/37273064#comment4, ACTION_PHONE_STATE_CHANGED (android.intent.action.PHONE_STATE) will be whitelisted for the Android O release. Though they may be replaced with a different mechanism in a future release.
I would like my app to wake up after it has been updated using the market (play store).
How can I accomplish that?
By waking up, I mean the Application.onCreate() to be executed.
As Commonsware mentions, the ACTION_PACKAGE_REPLACED does the trick. You just need to compare your package name with the data for the intent, otherwise you catch all packages being replaced.
In newer API's (12 on up) there is the ACTION_MY_PACKAGE_REPLACED which is only sent to the application that was replaced.
In principle, having a manifest-registered receiver for ACTION_PACKAGE_REPLACED should have this effect. Android should have to terminate your process to do the update, causing a fresh process to be created to deliver this broadcast to you.
That being said, I haven't tried this.
For example, if I want to know when Youtube is opened, is there any broadcast associated with it? I know of course I can poll the logcat message to check the activity. But can I do it through broadcast since it will be much less power-hungry.
This link seems to indicate it is impossible:<
How to Track App Usage in Android? How to detect when an activity is launched?
In adroid, is there any broadcast when some app is opend?
No, for obvious privacy reasons.
I have a app that has call blocking feature in it and that work is done by class BroadcastReceiver. When I install this app, the call is blocked always no matter what. How to get rid of this? I want this app to be active only when App is up and running . If I stop the service the App should not block the call. Thank you any help will be appreciated.
Are you the developer, or a user? If the latter, then you need to bring it up to the programmer of the app. If the former, then simply don't respond to the received broadcast when the app is not "active".