Android 解锁屏幕时启动服务

Android 解锁屏幕时启动服务,android,service,Android,Service,解锁屏幕时如何启动服务?也许有点像AlarmAanger context.startService(new Intent(context, Widget.class)); 用于检测屏幕打开和屏幕关闭寄存器广播接收器,如: AndroidManifest.xml: <receiver android:name="receiverScreen"> <intent-filter> <action android:name="a

解锁屏幕时如何启动服务?也许有点像AlarmAanger

context.startService(new Intent(context, Widget.class));

用于检测屏幕打开和屏幕关闭寄存器广播接收器,如:

AndroidManifest.xml:

 <receiver android:name="receiverScreen">
        <intent-filter> 
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.Intent.ACTION_USER_PRESENT" />
        </intent-filter> 
    </receiver>
系统通知您屏幕是否打开/关闭的接收器代码:

public class receiverScreen extends BroadcastReceiver {

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

         if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){

         }
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){

         }
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){

         }
     }

    }

用于检测屏幕打开和屏幕关闭寄存器广播接收器,如:

AndroidManifest.xml:

 <receiver android:name="receiverScreen">
        <intent-filter> 
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.Intent.ACTION_USER_PRESENT" />
        </intent-filter> 
    </receiver>
系统通知您屏幕是否打开/关闭的接收器代码:

public class receiverScreen extends BroadcastReceiver {

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

         if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){

         }
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){

         }
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){

         }
     }

    }