我在AndroidManifest.xml中定義一個BroadcastReceiver如下廣播接收器的onReceive是沒有得到所謂的
<receiver
android:name="com.example.hello.ScreenUnlockReceiver"
android:enabled="true"
android:singleUser="true">
<intent-filter>
<action android:name="android.content.Intent.ACTION_USER_PRESENT" />
</intent-filter>
</receiver>
,並定義如下接收器:
public class ScreenUnlockReceiver
extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//start activity
Intent i = new Intent();
i.setClassName("com.example.hello", "LoginActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
但是,當我解開廣播接收器不會被觸發屏幕和LoginActivity未顯示。 LoginActivity是android sdk自帶的默認loginactivity。
我是否在使用權限或其他內容中丟失了某些內容,請讓我知道。 感謝
Santhosh
檢查rciovati回答其絕對正確 – juned 2013-05-03 11:02:17