Sending intent to BroadcastReceiver from adb
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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:
C:Usersi.yesilevsky>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.whereismywifeser
ver.IntentReceiver} does not exist.
When I create intent in code, everything works fine. So how can I send intent from adb?
android android-intent broadcastreceiver adb
add a comment |
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:
C:Usersi.yesilevsky>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.whereismywifeser
ver.IntentReceiver} does not exist.
When I create intent in code, everything works fine. So how can I send intent from adb?
android android-intent broadcastreceiver adb
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
99
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
1
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21
add a comment |
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:
C:Usersi.yesilevsky>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.whereismywifeser
ver.IntentReceiver} does not exist.
When I create intent in code, everything works fine. So how can I send intent from adb?
android android-intent broadcastreceiver 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:
C:Usersi.yesilevsky>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.whereismywifeser
ver.IntentReceiver} does not exist.
When I create intent in code, everything works fine. So how can I send intent from adb?
android android-intent broadcastreceiver adb
android android-intent broadcastreceiver adb
edited May 15 '17 at 22:57
XIII-th
3,25821839
3,25821839
asked Mar 25 '14 at 12:21
user2106655user2106655
449158
449158
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
99
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
1
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21
add a comment |
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
99
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
1
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
99
99
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
1
1
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21
add a comment |
7 Answers
7
active
oldest
votes
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.
1
For some reason broadcast can't reach receiver if string extra (test from adb
in above example) contain whitespaces. Otherwise it works.
– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
It turns out, you do need-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.
– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
add a comment |
I've found that the command was wrong, correct command contains "broadcast" instead of "start":
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb" -n com.whereismywifeserver/.IntentReceiver
add a comment |
The true way to send a broadcast from ADB command is :
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
And, -a
means ACTION, --es
means to send a String extra.
PS. There are other data type you can send by specifying different params like:
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer)
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long)
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float)
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String; to embed a comma into a string,
escape it using ",")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using ",")
[-f <FLAG>]
For example, you can send an int value by:
--ei int_key 0
Very helpful.. thanks
– Maher Abuthraa
2 days ago
add a comment |
As many already noticed, the problem manifests itself only if the extra string contains whitespaces.
The root cause is that OP's host OS/shell (i.e. Windows/cmd.exe) mangles the entered command - the "
characters get lost, --es sms_body "test from adb"
becomes --es sms_body test from adb
. Which results in sms_body
string extra getting assigned the value of test
and the rest of the string becoming <URI>|<PACKAGE>|<COMPONENT>
specifier.
To avoid all that you could use:
adb shell "am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body 'test from adb' -n com.whereismywifeserver/.IntentReceiver"
or just start the interactive adb shell
session first and run the am broadcast
command from inside of it.
add a comment |
Another thing to keep in mind: Android 8 limits the receivers that can be registered via manifest (e.g., statically)
https://developer.android.com/guide/components/broadcast-exceptions
add a comment |
I had the same problem and found out that you have to escape spaces in the extra:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
So instead of "test from adb" it should be "test from adb"
add a comment |
Noting down my situation here may be useful to somebody,
I have to send a custom intent with multiple intent extras to a broadcast receiver in Android P,
The details are,
Receiver name: com.hardian.testservice.TestBroadcastReceiver
Intent action = "com.hardian.testservice.ADD_DATA"
intent extras are,
- "text"="test msg",
- "source"= 1,
Run the following in command line.
adb shell "am broadcast -a com.hardian.testservice.ADD_DATA --es text 'test msg' --es source 1 -n com.hardian.testservice/.TestBroadcastReceiver"
Hope this helps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22634446%2fsending-intent-to-broadcastreceiver-from-adb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
1
For some reason broadcast can't reach receiver if string extra (test from adb
in above example) contain whitespaces. Otherwise it works.
– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
It turns out, you do need-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.
– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
add a comment |
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.
1
For some reason broadcast can't reach receiver if string extra (test from adb
in above example) contain whitespaces. Otherwise it works.
– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
It turns out, you do need-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.
– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
add a comment |
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.
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.
edited Feb 21 at 8:59
rm -rf star
1,2921435
1,2921435
answered Mar 25 '14 at 14:14
Zohra KhanZohra Khan
3,63921731
3,63921731
1
For some reason broadcast can't reach receiver if string extra (test from adb
in above example) contain whitespaces. Otherwise it works.
– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
It turns out, you do need-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.
– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
add a comment |
1
For some reason broadcast can't reach receiver if string extra (test from adb
in above example) contain whitespaces. Otherwise it works.
– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
It turns out, you do need-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.
– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
1
1
For some reason broadcast can't reach receiver if string extra (
test from adb
in above example) contain whitespaces. Otherwise it works.– user2137020
Jan 23 '18 at 9:58
For some reason broadcast can't reach receiver if string extra (
test from adb
in above example) contain whitespaces. Otherwise it works.– user2137020
Jan 23 '18 at 9:58
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
I have the same issue as @user2137020
– Xi Wei
Apr 27 '18 at 7:16
2
2
It turns out, you do need
-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.– Xi Wei
Apr 27 '18 at 7:22
It turns out, you do need
-n com.whereismywifeserver/.IntentReceiver
if you want the string extra.– Xi Wei
Apr 27 '18 at 7:22
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
Is there a way to send broadcast like this with flags ?
– iammrmehul
Feb 7 at 5:03
add a comment |
I've found that the command was wrong, correct command contains "broadcast" instead of "start":
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb" -n com.whereismywifeserver/.IntentReceiver
add a comment |
I've found that the command was wrong, correct command contains "broadcast" instead of "start":
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb" -n com.whereismywifeserver/.IntentReceiver
add a comment |
I've found that the command was wrong, correct command contains "broadcast" instead of "start":
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb" -n com.whereismywifeserver/.IntentReceiver
I've found that the command was wrong, correct command contains "broadcast" instead of "start":
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb" -n com.whereismywifeserver/.IntentReceiver
answered Mar 25 '14 at 13:46
user2106655user2106655
449158
449158
add a comment |
add a comment |
The true way to send a broadcast from ADB command is :
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
And, -a
means ACTION, --es
means to send a String extra.
PS. There are other data type you can send by specifying different params like:
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer)
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long)
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float)
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String; to embed a comma into a string,
escape it using ",")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using ",")
[-f <FLAG>]
For example, you can send an int value by:
--ei int_key 0
Very helpful.. thanks
– Maher Abuthraa
2 days ago
add a comment |
The true way to send a broadcast from ADB command is :
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
And, -a
means ACTION, --es
means to send a String extra.
PS. There are other data type you can send by specifying different params like:
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer)
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long)
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float)
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String; to embed a comma into a string,
escape it using ",")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using ",")
[-f <FLAG>]
For example, you can send an int value by:
--ei int_key 0
Very helpful.. thanks
– Maher Abuthraa
2 days ago
add a comment |
The true way to send a broadcast from ADB command is :
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
And, -a
means ACTION, --es
means to send a String extra.
PS. There are other data type you can send by specifying different params like:
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer)
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long)
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float)
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String; to embed a comma into a string,
escape it using ",")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using ",")
[-f <FLAG>]
For example, you can send an int value by:
--ei int_key 0
The true way to send a broadcast from ADB command is :
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
And, -a
means ACTION, --es
means to send a String extra.
PS. There are other data type you can send by specifying different params like:
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer)
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long)
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float)
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String; to embed a comma into a string,
escape it using ",")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using ",")
[-f <FLAG>]
For example, you can send an int value by:
--ei int_key 0
answered Dec 18 '18 at 8:50
CalvinCheCalvinChe
36126
36126
Very helpful.. thanks
– Maher Abuthraa
2 days ago
add a comment |
Very helpful.. thanks
– Maher Abuthraa
2 days ago
Very helpful.. thanks
– Maher Abuthraa
2 days ago
Very helpful.. thanks
– Maher Abuthraa
2 days ago
add a comment |
As many already noticed, the problem manifests itself only if the extra string contains whitespaces.
The root cause is that OP's host OS/shell (i.e. Windows/cmd.exe) mangles the entered command - the "
characters get lost, --es sms_body "test from adb"
becomes --es sms_body test from adb
. Which results in sms_body
string extra getting assigned the value of test
and the rest of the string becoming <URI>|<PACKAGE>|<COMPONENT>
specifier.
To avoid all that you could use:
adb shell "am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body 'test from adb' -n com.whereismywifeserver/.IntentReceiver"
or just start the interactive adb shell
session first and run the am broadcast
command from inside of it.
add a comment |
As many already noticed, the problem manifests itself only if the extra string contains whitespaces.
The root cause is that OP's host OS/shell (i.e. Windows/cmd.exe) mangles the entered command - the "
characters get lost, --es sms_body "test from adb"
becomes --es sms_body test from adb
. Which results in sms_body
string extra getting assigned the value of test
and the rest of the string becoming <URI>|<PACKAGE>|<COMPONENT>
specifier.
To avoid all that you could use:
adb shell "am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body 'test from adb' -n com.whereismywifeserver/.IntentReceiver"
or just start the interactive adb shell
session first and run the am broadcast
command from inside of it.
add a comment |
As many already noticed, the problem manifests itself only if the extra string contains whitespaces.
The root cause is that OP's host OS/shell (i.e. Windows/cmd.exe) mangles the entered command - the "
characters get lost, --es sms_body "test from adb"
becomes --es sms_body test from adb
. Which results in sms_body
string extra getting assigned the value of test
and the rest of the string becoming <URI>|<PACKAGE>|<COMPONENT>
specifier.
To avoid all that you could use:
adb shell "am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body 'test from adb' -n com.whereismywifeserver/.IntentReceiver"
or just start the interactive adb shell
session first and run the am broadcast
command from inside of it.
As many already noticed, the problem manifests itself only if the extra string contains whitespaces.
The root cause is that OP's host OS/shell (i.e. Windows/cmd.exe) mangles the entered command - the "
characters get lost, --es sms_body "test from adb"
becomes --es sms_body test from adb
. Which results in sms_body
string extra getting assigned the value of test
and the rest of the string becoming <URI>|<PACKAGE>|<COMPONENT>
specifier.
To avoid all that you could use:
adb shell "am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body 'test from adb' -n com.whereismywifeserver/.IntentReceiver"
or just start the interactive adb shell
session first and run the am broadcast
command from inside of it.
answered Jun 7 '18 at 19:22
Alex P.Alex P.
20.7k1369121
20.7k1369121
add a comment |
add a comment |
Another thing to keep in mind: Android 8 limits the receivers that can be registered via manifest (e.g., statically)
https://developer.android.com/guide/components/broadcast-exceptions
add a comment |
Another thing to keep in mind: Android 8 limits the receivers that can be registered via manifest (e.g., statically)
https://developer.android.com/guide/components/broadcast-exceptions
add a comment |
Another thing to keep in mind: Android 8 limits the receivers that can be registered via manifest (e.g., statically)
https://developer.android.com/guide/components/broadcast-exceptions
Another thing to keep in mind: Android 8 limits the receivers that can be registered via manifest (e.g., statically)
https://developer.android.com/guide/components/broadcast-exceptions
answered Oct 13 '18 at 1:24
YangYang
8827
8827
add a comment |
add a comment |
I had the same problem and found out that you have to escape spaces in the extra:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
So instead of "test from adb" it should be "test from adb"
add a comment |
I had the same problem and found out that you have to escape spaces in the extra:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
So instead of "test from adb" it should be "test from adb"
add a comment |
I had the same problem and found out that you have to escape spaces in the extra:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
So instead of "test from adb" it should be "test from adb"
I had the same problem and found out that you have to escape spaces in the extra:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
So instead of "test from adb" it should be "test from adb"
answered Feb 13 at 10:10
melbicmelbic
8,20852433
8,20852433
add a comment |
add a comment |
Noting down my situation here may be useful to somebody,
I have to send a custom intent with multiple intent extras to a broadcast receiver in Android P,
The details are,
Receiver name: com.hardian.testservice.TestBroadcastReceiver
Intent action = "com.hardian.testservice.ADD_DATA"
intent extras are,
- "text"="test msg",
- "source"= 1,
Run the following in command line.
adb shell "am broadcast -a com.hardian.testservice.ADD_DATA --es text 'test msg' --es source 1 -n com.hardian.testservice/.TestBroadcastReceiver"
Hope this helps.
add a comment |
Noting down my situation here may be useful to somebody,
I have to send a custom intent with multiple intent extras to a broadcast receiver in Android P,
The details are,
Receiver name: com.hardian.testservice.TestBroadcastReceiver
Intent action = "com.hardian.testservice.ADD_DATA"
intent extras are,
- "text"="test msg",
- "source"= 1,
Run the following in command line.
adb shell "am broadcast -a com.hardian.testservice.ADD_DATA --es text 'test msg' --es source 1 -n com.hardian.testservice/.TestBroadcastReceiver"
Hope this helps.
add a comment |
Noting down my situation here may be useful to somebody,
I have to send a custom intent with multiple intent extras to a broadcast receiver in Android P,
The details are,
Receiver name: com.hardian.testservice.TestBroadcastReceiver
Intent action = "com.hardian.testservice.ADD_DATA"
intent extras are,
- "text"="test msg",
- "source"= 1,
Run the following in command line.
adb shell "am broadcast -a com.hardian.testservice.ADD_DATA --es text 'test msg' --es source 1 -n com.hardian.testservice/.TestBroadcastReceiver"
Hope this helps.
Noting down my situation here may be useful to somebody,
I have to send a custom intent with multiple intent extras to a broadcast receiver in Android P,
The details are,
Receiver name: com.hardian.testservice.TestBroadcastReceiver
Intent action = "com.hardian.testservice.ADD_DATA"
intent extras are,
- "text"="test msg",
- "source"= 1,
Run the following in command line.
adb shell "am broadcast -a com.hardian.testservice.ADD_DATA --es text 'test msg' --es source 1 -n com.hardian.testservice/.TestBroadcastReceiver"
Hope this helps.
answered Nov 30 '18 at 20:43
HardianHardian
605711
605711
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22634446%2fsending-intent-to-broadcastreceiver-from-adb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
possible duplicate of Send Intent to App in Emulator
– janot
Sep 28 '14 at 7:09
99
did you finally find her?
– Jmorvan
Jan 12 '15 at 23:46
1
best comment ever @Jmorvan !!
– Juancho
Jan 17 at 20:21