Emulate broadcast on Android

I need to know how to emulate a broadcastreceiver .

I have the following code, but I have no idea how to really see when it receives a broadcast.

 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()); } } 

In my manifest, I have the following:

 <receiver android:name="com.dennis.test.LocationBroadcastReceiver"> <intent-filter> <action android:name="android.location.LocationManager.KEY_LOCATION_CHANGED" /> </intent-filter> </receiver> 
+3
source share
2 answers

Go to the folder where your android-sdk is installed, and then to the platform tools. There will be several executable files. One of them is adb.

In the folder, do

./adb shell am broadcast -a android.intent.action.KEY_LOCATION_CHANGED -c android.intent.category.HOME -n com.dennis.test / .LocationBroadcastReceiver

or on the windows

adb shell am broadcast -a android.intent.action.KEY_LOCATION_CHANGED -c android.intent.category.HOME -n com.dennis.test / .LocationBroadcastReceiver

+7
source

You should also use MockLocation to generate from your executable or JUnit. I have not used it, but that is its purpose.

It is probably functionally similar to @ user1258903's answer, but should be able to send remote locations (e.g. North Pole, mom's house, ocean floor, etc.). This way you can check your calculations and integration maps, etc., that you might have.

How to emulate GPS location in Android emulator?

0
source

All Articles