Skip to content

Instantly share code, notes, and snippets.

@simlegate
Last active April 14, 2021 02:44
Show Gist options
  • Select an option

  • Save simlegate/5545512 to your computer and use it in GitHub Desktop.

Select an option

Save simlegate/5545512 to your computer and use it in GitHub Desktop.

Revisions

  1. simlegate revised this gist May 9, 2013. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions manifest.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.simlegate.saveresource"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15" />

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
    android:name=".MainActivity"
    android:label="@string/title_activity_main" >
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <receiver android:name=".ScreenActionReceiver">
    <intent-filter android:priority="90000">
    <action android:name="android.intent.action.USER_PRESENT" />
    </intent-filter>
    </receiver>


    </application>

    </manifest>
  2. simlegate revised this gist May 9, 2013. 1 changed file with 45 additions and 0 deletions.
    45 changes: 45 additions & 0 deletions ScreenActionReceiver.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    package com.simlegate.saveresource;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.util.Log;

    public class ScreenActionReceiver extends BroadcastReceiver {

    private String TAG = "ScreenActionReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {


    String action = intent.getAction();


    if(Intent.ACTION_SCREEN_ON.equals(action))
    {
    Log.d(TAG, "screen is on...");

    }

    else if(Intent.ACTION_SCREEN_OFF.equals(action))
    {
    Log.d(TAG, "screen is off...");
    }

    else if(Intent.ACTION_USER_PRESENT.equals(action))
    {
    Log.d(TAG, "screen is unlock...");
    }

    }

    public IntentFilter getFilter(){
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    return filter;
    }

    }
  3. simlegate created this gist May 9, 2013.
    21 changes: 21 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    package com.simlegate.saveresource;

    import android.app.Activity;

    import android.os.Bundle;

    public class MainActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    final ScreenActionReceiver screenactionreceiver = new ScreenActionReceiver();

    registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
    }

    }