0
我認爲在代碼中一切都很完美,但我無法在廣播接收器中接收廣播。無法接收來自活動的廣播
這裏是我的活動
public class BroadcastDemo extends Activity {
Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button)findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
Intent broadint = new Intent();
broadint.setAction("SENT_BROADCAST");
getApplicationContext().sendBroadcast(broadint);
Log.e("Dillu","BroadCast is sent");
}
});
}
}
這裏是廣播接收機
public class ReceiveBroadcast extends BroadcastReceiver{
@Override
public void onReceive(Context con,Intent inte){
Log.e("Dillu","Receiving the BroadCast");
if(inte.getAction().equals("SENT_BROADCAST"))
Toast.makeText(con, "Received BroadCast Succesfully", Toast.LENGTH_LONG).show();
Log.e("Dillu","Received the BroadCast");
}
}
這裏是清單文件中註冊的接收器
<Receiver
android:name=".ReceiveBroadcast">
<intent-filter>
<action android:name="SENT_BROADCAST"></action>
</intent-filter>
</Receiver>
廣播接收器無法接收從活動發送的廣播。我不知道我出錯的地方。
是否設置所需的權限? – Stuti 2012-02-07 13:17:01
@Stuti - 活動和廣播接收器都在同一個應用程序中。我應該保留哪些權限? – 2012-02-07 13:24:24