Sending intent to BroadcastReceiver from adb

前端 未结 8 1764
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 20:26

I\'ve got BroadcastReceiver class:

public class IntentReceiver extends BroadcastReceiver {

    final String tag = \"Intent Intercepter\";

    @Override
            


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 20:49

    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 || 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.

提交回复
热议问题