我在学习使用Android BroadcasReceiver。 我写了这段代码,但它不工作...我尝试了例如改变时间等... 这是什么错误?为什么我的BroadcastReceiver不起作用?
我在清单补充说:
<receiver android:name="com.example.broadcastreceiverspike.Broadcast" >
<intent-filter android:priority="100">
<action android:name="android.intent.action.ACTION_SCREEN_ON" />
<action android:name="android.intent.action.ACTION_SCREEN_OFF" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
我简单BroadcasReceiver:
public class Broadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("BROADCAST", "It worked");
Toast.makeText(context, "BROADCAST", Toast.LENGTH_LONG).show();
}
}
我的主要活动(默认的主活动)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
http://stackoverflow.com/questions/7714731/broadcastreceiver-for-screen-lock-没有被触发你检查 –
谢谢它的作品。我在 –