我需要知道如何模拟一个广播接收器(broadcastreceiver
)。
我有以下代码,但我不知道如何查看它是否接收到广播信号。
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>