Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending intent to BroadcastReceiver from adb

I've got BroadcastReceiver class:

public class IntentReceiver extends BroadcastReceiver {      final String tag = "Intent Intercepter";      @Override     public void onReceive(Context context, Intent intent) {         try {             String data = intent.getStringExtra("sms_body");             Log.i(tag, data);             Toast.makeText(context, data.subSequence(0, data.length()), Toast.LENGTH_LONG).show();         } catch (Exception e) {             Toast.makeText(context, "Intercepted", Toast.LENGTH_LONG).show();         }     } } 

And also in manifest:

<receiver android:name="com.whereismywifeserver.IntentReceiver" android:enabled="true">     <intent-filter android:priority="999">         <action android:name="com.whereismywifeserver.intent.TEST"/>     </intent-filter> </receiver> 

But when I try to send intent from adb, I receive error:

$ adb shell am start  -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"  -c android.intent.category.HOME  -n com.whereismywifeserver/.IntentReceiver Starting: Intent { act=com.whereismywifeserver.intent.TEST t=[android.intent.category.HOME] cmp=com.whereismywifeserver/.IntentReceiver (has extras) } Error type 3 Error: Activity class {com.whereismywifeserver/com.whereismywifeserver.IntentReceiver} does not exist. 

When I create intent in code, everything works fine. So how can I send intent from adb?

like image 939
user2106655 Avatar asked Mar 25 '14 12:03

user2106655


People also ask

How do I start an intent using adb?

You can use the start command from Activity Manager (am) a.k.a the adb shell am start -n command (via adb) specifying the app package name and the component name as defined in the manifest. You can add other parameters like ACTION (-a android. intent.

What is adb Intent?

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.

What does adb broadcast do?

Android ADB (Android Debug Bridge) Sending broadcast To send intent to specific package/class -n or -p parameter can be used. Useful examples: Sending a "boot complete" broadcast. Sending a "time changed" broadcast after setting time via adb command.


1 Answers

You need not specify receiver. You can use adb instead.

adb shell am broadcast -a com.whereismywifeserver.intent.TEST  --es sms_body "test from adb" 

For more arguments such as integer extras, see the documentation.

like image 199
Zohra Khan Avatar answered Sep 27 '22 20:09

Zohra Khan