Is it possible to somehow detect when a user goes to a page from within an service (or broadcast receiver) ? I would like to add a feature on my app which detects whenever the user goes to mysite.com, and show an alertdialog asking if the user wants to launch the app for a more convenient experience.
add: i should add that my app is used to browse data from mysite.com much easier.
Related
So, I'm building a Ride Hailing app and I'm still not sure of what route should I go with for alerting a user for a New Ride Reuest.
Should I go with Draw Over Other Apps to open the activity when the notification is received.
Should I use fullScreenNotificationIntent with showOnLockScreen
And if I use fullScreenNotificationIntent, the Android system not always open the activity, it shows a headsupNotification, and I will have to add and handle accept reject actions.
Need a proper professional suggestion on this.
In android, is there anyway to detect that a foreground app's button is clicked? I am not talking about my own app, I mean detect globally a button press event.
For exapmle, skype is running in foreground, I'd like to detect when user clicked a button in skype.
=====UPDATE=====
If the answer of above question is no, is there a way to detect window focus change OR dialog popup globally?
the answer is no and no.
That is by design and it's a "security feature". Android is sandboxed, apps operate on separate Windows and separate processes and are not supposed to know about each other. Unless the specific app is broadcasting something, there's no way to external apps to access it.
Try to imagine what a HUGE security flaw that would be to have that type of access.
malicious code is installed with permission to receive "global clicks" and "draw on top of other apps".
user installs banking app
user click on login on banking app
malicious code receive the click and draw on top of the app something that looks exactly like the banking app
user type his/her login details
malicious code transmit user details to remote server
developer of malicious code withdraw users money.
to conclude: I'm very happy that Android does not provide such functionality.
I am new in Android and is developing an app which runs in background as service to collect user activity. till now my app is able to get information about Time_Start, Time_End and Name of other app used by user.
I want to improve my app to be able to count how many interactions(like user tap, touch,...) user make while using other app.
any help?
Thanks!
AFAIK one can't catch touch events/key presses if they are outside your Activity's context or Application's context. I think it goes against the design principle in general ( every app. is sandboxed in its own DVM).
Also, Android has provided mechanism of Intents to track some specific actions and not evry interaction the user has with the mobile . So, I don't think it seems possible .
I am writing a service to collect location readings while my application is running in the foreground. In the LocationListener, I would like to use the onProviderDisabled() method to open a dialog telling the user that the location provider is disabled, and have a button on the dialog that will launch the system's location settings panel, allowing the user to enable the location provider if they choose. If this was an activity, I would launch the system settings using startActivityforResult(), but I can only use startActivity from a service.
My question is this: is there a way I can open the settings from a service, and have this new activity close and return to my application after the user changes a setting?
EDIT: What I'm trying to achieve is a Service running from the moment the application opens until it closes and collecting location readings, maintaining a best estimate of location for use in the application. If the LocationListener within the service has onProviderDisabled called, I want this to cause a dialog to open that will give the user the option to go to the System Settings and enable location providers (or cancel and carry on, although some of the application's features won't work without location). I agree that the perhaps the Service isn't the place to do the dialog/activity launch part as it is a background component with no UI, but I'm not sure where the code for this should go.
From the edit to your question and the comment to Sam's answer, I'd basically do a check in the Activity (or all Activities) of the app and launch the dialog and subsequent 'Settings' page from there (if the user chooses to go to Settings).
Basically, have the Service do what it needs to based on the current environment the main Activity encounters (provider disabled/enabled). If your Service will be running when there is no user front-end then have it compensate and reduce its 'duties' accordingly.
Also, in that scenario, Sam's idea of using a notification (which in turn could cause the Settings to be opened) is a good middle ground.
EDIT To explain a little further. Take something as simple as an email app. There are two aspects to this...
Firstly there's a UI - when the user opens their email app if 'the network' is disabled the user is told so with a dialog with the option to go to network settings to enable the network. Pressing BACK (from Settings) will return to the email app and it will attempt to download any new emails. If the user decides not to enable the network they can still view previously downloaded emails (similar to partial functionality in you situation).
Secondly there is a background service which periodically (every 15 mins, 30 mins, 1 hr etc) will attempt to download any new emails even if the UI is closed. If the network is disabled it will simply go to sleep (until next download time).
In theory if a user disables the network, the background email service 'could' provide a dialog or notification to say "You do realise I can't work now?"...this is kind of what you want to do BUT if the service has other things to do it can simply do those and ignore any network-related tasks. Next time the user fires up the Activity, they then get a dialog with the option to enable the network.
Does that make more sense?
Yes, Service has the ContextWrapper.startActivity() method which will open the desired Settings menu. The user will select what they would like to enable then touch back to return your Activity. Once back in your activity you can check LocationManager.isProviderEnabled(). Unfortunately a service cannot take an Activity result.
just curious. service may run even if the user is not seeing the screen, or even the screen may be turned off. is it a good idea, showing a dialog from the service.
anyway, since you know how to show an activity, in the onCreate fire the intent for the settings and finish it once you get to onActivityResult.
sure this is a simple hack.
EDIT: if you are not sure where it should go. the best i can think, and even seen in some apps is the notification area.
I want to create an app or background service that just listens for the launch of a 'default' app, say Contacts or the built-in Gmail app. If the contact app is clicked, I want to transfer control to my app temporarily (e.g. present a Yes/No popup to the user or increment an internal counter of my app ) and then redirect the user back to the app that was clicked. I want to do this only for a couple of 'well-known' built-in default apps, not any third party apps.
Is this possible? May be using some special intents?
Have you tried registering broadcast receivers for the intents that would launch those built-in apps? This might not work since that might confuse Android into thinking your app is a potential target for those intents (e.g. that it should be used to actually write and send the email in the case of a 'compose an email' intent), but it should be a good place to start.