Android Question Can I detect Home button press without replacing home function?

JohnC

Expert
Licensed User
Longtime User
I want to know when a user is viewing the home screen. One way is to detect the pressing of the home button.

Normally if you hook into the home button (like when you install a new launcher), it requires the user to select your app using the popup "'One time only' or 'Always'" dialog to assign the intent to your app. But what I am wondering is if there is a way to detect when the home button is pressed without disturbing the phones settings or require the user to do anything with my app to do this?
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
You can detect if the home screen is up.
You can use this library. look at getForegroundApp method and check for 'com.android.launcher'
It can tell you if the Launcher is the foreground app.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The suggestion to check for "com.android.launcher" is a very good one and I will probably use it if I can't find another non-poll method.

But, I just thought of something...If I create a homescreen widget...:
1) Is there an event that will get triggered when the user goes and displays the homescreen (which causes the widget's icon to display)?
2) And if there is a widget event to detect when the homescreen gets displayed, will this event trigger even if the user is viewing a homescreen page that is different from the homescreen page the widget icon is on?
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
ohhhh, good idea, do not know as I have never done a widget. But if that does work I will change over the way I am doing it.
 
Upvote 0
Top