gpt4 book ai didi

android - 从 adb 向 BroadcastReceiver 发送 Intent

转载 作者:IT王子 更新时间:2023-10-29 00:07:59 29 4
gpt4 key购买 nike

我有 BroadcastReceiver 类:

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

而且在 list 中:

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

但是当我尝试从 adb 发送 Intent 时,我收到错误:

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

当我在代码中创建 Intent 时,一切正常。那么如何从 adb 发送 Intent 呢?

最佳答案

您无需指定接收方。你可以用 adb 代替。

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

有关更多参数,例如整数附加值,请参阅 documentation .

关于android - 从 adb 向 BroadcastReceiver 发送 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22634446/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com