Broadcasting and receiving extra doubles

前端 未结 1 1662
故里飘歌
故里飘歌 2020-12-18 17:04

I\'m attempting to broadcast extras in an am broadcast in adb shell. In my BroadcastReceiver in android, I\'m subscribed to the broadcast and pull the extras out of the Bund

相关标签:
1条回答
  • 2020-12-18 17:48

    You can use URI format to provide <INTENT> to am broadcast and am startservice:

    adb shell am broadcast "intent:#Intent;action=android.intent.action.YOUR_ACTION;d.percent_complete=99.999;end"
    

    URI format supports the following extra types:

    Bundle b = intent.mExtras;
    if      (uri.startsWith("S.", i)) b.putString(key, value);
    else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
    else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
    else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
    else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
    else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
    else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
    else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
    else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
    else throw new URISyntaxException(uri, "unknown EXTRA type", i);
    
    0 讨论(0)
提交回复
热议问题