]> average.org Git - WhereAmI.git/commitdiff
implement autostart on boot
authorEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 22:07:32 +0000 (02:07 +0400)
committerEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 22:07:32 +0000 (02:07 +0400)
AndroidManifest.xml
res/values/strings.xml
res/xml/preferences.xml
src/org/average/whereami/Autostart.java [new file with mode: 0644]

index 5ec033454772c63c739fe5211e0bab45c970120e..f570fecd1618d077414858f3c7fd09e2924afb4d 100644 (file)
@@ -6,6 +6,7 @@
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
     <uses-sdk android:minSdkVersion="8"/>
     <supports-screens android:largeScreens="true"/>
     <application android:label="@string/app_name"
         <activity android:name="WhereAmIprefs"
                   android:label="@string/app_name">
         </activity>
+        <receiver android:name="Autostart">
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+            </intent-filter>
+        </receiver>
     </application>
 </manifest> 
index 32d38e3d1683c9e06cc588cb96c712bcf68e1cad..1e8e10e813d8b63c45be81632540a31eba6e1f76 100644 (file)
@@ -24,6 +24,8 @@
     <string name="quit">Выход</string>
     <string name="authorize">Авторизация</string>
     <string name="settings">Конфигурация</string>
+    <string name="autostarttitle">Автостарт</string>
+    <string name="autostartsummary">Автоматический запуск при загрузке</string>
     <string name="fullscreentitle">Полный экран</string>
     <string name="fullscreensummary">Полный экран или с индикаторами</string>
     <string name="managewifititle">Управление WiFi</string>
index a74d5b4a4548fe107284209aeef16d881103e611..51800dac3f08e7cf887e697b3bb80b52135c6120 100644 (file)
@@ -1,5 +1,11 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+    <CheckBoxPreference
+      android:key="autostart"
+      android:title="@string/autostarttitle"
+      android:summary="@string/autostartsummary"
+      android:defaultValue="false"
+    />
     <CheckBoxPreference
       android:key="fullscreen"
       android:title="@string/fullscreentitle"
diff --git a/src/org/average/whereami/Autostart.java b/src/org/average/whereami/Autostart.java
new file mode 100644 (file)
index 0000000..1778905
--- /dev/null
@@ -0,0 +1,28 @@
+package org.average.whereami;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+public class Autostart extends BroadcastReceiver {
+
+       final String TAG = getClass().getName();
+
+       @Override
+       public void onReceive(Context context, Intent intent) {
+               SharedPreferences prefs =
+                       PreferenceManager.getDefaultSharedPreferences(context);
+               if (prefs.getBoolean("autostart", false)) {
+                       Log.v(TAG, "Activating WhereAmI");
+                       Intent i = new Intent(context, WhereAmI.class);
+                       i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                       context.startActivity(i);
+               } else {
+                       Log.v(TAG, "Ignoring BOOT_COMPLETED event");
+               }
+       }
+}