首页 > 代码库 > PowerManager使用实例1(下)

PowerManager使用实例1(下)

文件2 layout\main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <Button
    android:id="@+id/Button0" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
    <Button
    android:id="@+id/Button1" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<Button
android:id="@+id/Button2" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<Button
android:id="@+id/Button3" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<Button
android:id="@+id/Button4" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<Button
android:id="@+id/Button5" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
<Button
android:id="@+id/Button6" 
android:text="@string/sleep"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
<Button
android:id="@+id/Button7" 
android:text="@string/reboot"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
</LinearLayout>
<Button
android:id="@+id/Button8" 
android:text="@string/userActivity"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></Button>
</LinearLayout>
文件3 values\strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, MainActivity!</string>
    <string name="app_name">PowerMangerSample</string>
     <string name="acquire_PARTIAL">acquire PARTIAL_WAKE_LOCK</string>
     <string name="release_PARTIAL">release PARTIAL_WAKE_LOCK</string>
     <string name="acquire_SCREEN_DIM">acquire SCREEN_DIM_WAKE_LOCK</string>
     <string name="release_SCREEN_DIM">release SCREEN_DIM_WAKE_LOCK</string>
     <string name="acquire_SCREEN_BRIGHT">acquire SCREEN_BRIGHT_WAKE_LOCK</string>
     <string name="release_SCREEN_BRIGHT">release SCREEN_BRIGHT_WAKE_LOCK</string>
     <string name="acquire_FULL_WAKE_LOCK">acquire FULL_WAKE_LOCK_WAKE_LOCK</string>
     <string name="release_FULL_WAKE_LOCK">release FULL_WAKE_LOCK_WAKE_LOCK</string>
     <string name="combineFlag0">combine with ACQUIRE_CAUSES_WAKEUP</string>
     <string name="notCombineFlag0">not combine with ACQUIRE_CAUSES_WAKEUP</string>
     <string name="combineFlag1">combine with ON_AFTER_RELEASE</string>
     <string name="notCombineFlag1">not combine with ON_AFTER_RELEASE</string>
     <string name="sleep">go sleep</string>
     <string name="reboot">reboot</string>
     <string name="userActivity">userActivity</string>
</resources>
文件4 values\ids.xml:
<resources>
    <item type="id" name="StateKey" />
    <item type="id" name="TextTurnOnKey" />
    <item type="id" name="TextTurnOffKey" />
</resources>
文件5 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.teleca.robin"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  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>
    <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DEVICE_POWER"/>
<uses-permission android:name="android.permission.REBOOT"/>
</manifest>