public class SmsBroadcastReceiver extends BroadcastReceiver {
static final String ACTION = "action";
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION)) { Toast.makeText(MainActivity.this, intent.get,Toast.LENGTH_LONG ).show(); } } }adb shell am broadcast -a test --es test_string "this is test string" 用这条命令来发送消息,上面的onReceive收不到。adb shell am broadcast -a test 这样就能收到,但就只有action,没法带入消息的内容唉
if (intent.getAction().equals(ACTION)) { Bundle bun = intent.getExtras(); String Msg1 = bun.getString("key");
菜鸟求指导。
{
static final String ACTION = "action";
@Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
Toast.makeText(MainActivity.this, intent.get,Toast.LENGTH_LONG ).show();
}
}
}adb shell am broadcast -a test --es test_string "this is test string"
用这条命令来发送消息,上面的onReceive收不到。adb shell am broadcast -a test
这样就能收到,但就只有action,没法带入消息的内容唉
{
Bundle bun = intent.getExtras();
String Msg1 = bun.getString("key");
}