2011-10-21 72 views

回答

10

使用接收器:

public class Receive extends BroadcastReceiver { 

if (intent.getAction() != null) { 
      if 
        (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { 
Intent s = new Intent(context, MainActivity.class); 
        s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

        context.startActivity(s); 
}} 

而在你的清單:

<receiver 
     android:name=".Receive" 
     android:enabled="true" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="android.intent.action.USER_PRESENT"/> 
     </intent-filter> 
    </receiver> 
+0

我用了你的代碼之上,但第一次我的鎖活動是開放的,但我認爲它程序自動調用後不知道當屏幕on.Why這個對話框時,爲什麼這個對話框打開而不是我的鎖定活動...請幫助快速謝謝... –

+0

我不會使用'android:exported =「false」'這也是不允許' '-Tag,參見http://stackoverflow.com/questions/29081414/why-wont-this-broadcast-receiver-wor K-在-棒棒糖#comment58423396_29274695 – OneWorld