broadcast receivers
authorEugene Crosser <crosser@average.org>
Fri, 3 May 2013 14:31:49 +0000 (18:31 +0400)
committerEugene Crosser <crosser@average.org>
Fri, 3 May 2013 14:31:49 +0000 (18:31 +0400)
AndroidManifest.xml
src/org/average/nfcauthcr/Autostart.java [new file with mode: 0644]
src/org/average/nfcauthcr/Autostop.java [new file with mode: 0644]

index 684cae96aabbb3512ba68c17805408f19c89b823..73d6683af9f33f0793296d2b3e6ff8b05be43ca4 100644 (file)
@@ -1,30 +1,42 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-      package="org.average.nfcauthcr"
-      android:versionCode="1"
-      android:versionName="1.0">
-    <uses-sdk android:minSdkVersion="10"
-              android:targetSdkVersion="17" />
+         package="org.average.nfcauthcr"
+         android:versionCode="1"
+         android:versionName="1.0">
+       <uses-sdk android:minSdkVersion="10"
+                 android:targetSdkVersion="17" />
 
-    <uses-permission android:name="android.permission.NFC" />
-    <uses-feature android:name="android.hardware.nfc"
-                  android:required="true" />
+       <uses-permission android:name="android.permission.NFC" />
+       <uses-feature android:name="android.hardware.nfc"
+                     android:required="true" />
 
-    <application android:label="@string/app_name"
-                 android:icon="@drawable/yalekey"
-                 android:allowBackup="true"
-                 android:theme="@style/AppTheme">
+       <application android:label="@string/app_name"
+                        android:icon="@drawable/yalekey"
+                        android:allowBackup="true"
+                        android:theme="@style/AppTheme">
 
-        <activity android:name=".Enroll"
-                  android:label="@string/app_name">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        <activity android:name=".Check"
-                  android:label="@string/app_name">
-        </activity>
+               <activity android:name=".Enroll"
+                         android:label="@string/app_name">
+                       <intent-filter>
+                               <action android:name="android.intent.action.MAIN" />
+                               <category android:name="android.intent.category.LAUNCHER" />
+                       </intent-filter>
+               </activity>
 
-    </application>
+               <receiver android:name=".Autostart">
+                       <intent-filter>
+                               <action android:name="android.intent.action.USER_PRESENT" />
+                       </intent-filter>
+               </receiver>
+               <receiver android:name=".Autostop">
+                       <intent-filter>
+                               <action android:name="android.intent.action.SCREEN_OFF" />
+                       </intent-filter>
+               </receiver>
+
+               <service android:name=".Check"
+                        android:label="@string/app_name">
+               </service>
+
+       </application>
 </manifest>
diff --git a/src/org/average/nfcauthcr/Autostart.java b/src/org/average/nfcauthcr/Autostart.java
new file mode 100644 (file)
index 0000000..755fe04
--- /dev/null
@@ -0,0 +1,21 @@
+package org.average.nfcauthcr;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import org.average.nfcauthcr.Check;
+
+public class Autostart extends BroadcastReceiver {
+
+       final String TAG = getClass().getName();
+
+       @Override
+       public void onReceive(Context context, Intent intent) {
+               Log.v(TAG, "Autostart called");
+               Intent i = new Intent(context, Check.class);
+               i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+               context.startService(i);
+       }
+}
diff --git a/src/org/average/nfcauthcr/Autostop.java b/src/org/average/nfcauthcr/Autostop.java
new file mode 100644 (file)
index 0000000..238104f
--- /dev/null
@@ -0,0 +1,20 @@
+package org.average.nfcauthcr;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import org.average.nfcauthcr.Check;
+
+public class Autostop extends BroadcastReceiver {
+
+       final String TAG = getClass().getName();
+
+       @Override
+       public void onReceive(Context context, Intent intent) {
+               Log.v(TAG, "Autostop called");
+               Intent i = new Intent(context, Check.class);
+               context.stopService(i);
+       }
+}