我需要知道如何模擬broadcastreceiver
。在Android中模擬廣播
我有下面的代碼,但我不知道如何真正看到它何時接收廣播。
public class LocationBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras();
Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
Toast.makeText(context, loc.toString(), Toast.LENGTH_SHORT).show();
Log.d("com.dennis.test","LOCATION: " + loc.toString());
}
}
在我的表現,我有以下:
<receiver android:name="com.dennis.test.LocationBroadcastReceiver">
<intent-filter>
<action android:name="android.location.LocationManager.KEY_LOCATION_CHANGED" />
</intent-filter>
</receiver>
對於你在manifest中註冊了什麼意圖? – user936414 2012-03-27 08:37:53