2

I want to make an application that would display a message when a user unlocks his/her Android phone. I do not know if this is possible or not.

If anyone has a way to do this, could you please point me in the right direction.

Matt
  • 74,352
  • 26
  • 153
  • 180
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74

3 Answers3

4

Only android.intent.action.USER_PRESENT action BroadcastReceiver is enough to do what you need

RPB
  • 16,006
  • 16
  • 55
  • 79
3

Yes you can do it by registering android.intent.action.USER_PRESENT in manifast as:

<receiver android:name=".unlockReceiver">
<intent-filter android:enabled="true" android:priority="90000" android:exported="false">
    <action android:name="android.intent.action.USER_PRESENT" />
    </intent-filter>
 </receiver>

and in unlockReceiver show message as:

public class unlockReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
    if( intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
       Toast msg = Toast.makeText(context,"hello User !!! :)", Toast.LENGTH_LONG);
        msg.show();
      }
    }
}
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
1

Yes you can do this

In your manifest file write this,

receiver android:name=".MyBroadCastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.HOME" />

            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>

and MyBroadCastReceiver implementation is like this

public class MyBroadCastReceiver extends BroadcastReceiver {

    Context mContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        Toast.makeText(mContext, "Phone UNLOCKED", Toast.LENGTH_LONG)
                .show();

    }

}
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
  • You can't register for the SCREEN_ON action in the manifest (http://stackoverflow.com/questions/1588061/android-how-to-receive-broadcast-intents-action-screen-on-off). – lseidman Feb 22 '13 at 16:41