2014-02-12 85 views
0

我試圖播放在adb外殼廣播的演員。在我的android的BroadcastReceiver中,我訂閱了廣播並將其他內容從Bundle中提取出來。廣播和接收額外的雙打

我的麻煩在於雙打。我以爲,一個廣播可以包括雙,因爲Bundle類有一個getDouble方法,例如:

double percentComplete = bundle.getDouble("percent_complete"); 

然而,亞行殼AM廣播命令似乎不支持雙打,只漂浮。當我發送float時,Bundle.getDouble()方法將引發一個內部異常,並在警告級別進行記錄,表明它無法將Float轉換爲Double。

我可以發送雙打,還是我被迫使用花車?

下面是我知道的額外細節的標誌,正如我報告的那樣。

<INTENT> specifications include these flags and arguments: 
    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] 
    [-c <CATEGORY> [-c <CATEGORY>] ...] 
    [-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...]] 
    [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]] 
    [--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]] 
    [-n <COMPONENT>] [-f <FLAGS>] 
    [--grant-read-uri-permission] [--grant-write-uri-permission] 
    [--debug-log-resolution] [--exclude-stopped-packages] 
    [--include-stopped-packages] 
    [--activity-brought-to-front] [--activity-clear-top] 
    [--activity-clear-when-task-reset] [--activity-exclude-from-recents] 
    [--activity-launched-from-history] [--activity-multiple-task] 
    [--activity-no-animation] [--activity-no-history] 
    [--activity-no-user-action] [--activity-previous-is-top] 
    [--activity-reorder-to-front] [--activity-reset-task-if-needed] 
    [--activity-single-top] [--activity-clear-task] 
    [--activity-task-on-home] 
    [--receiver-registered-only] [--receiver-replace-pending] 
    [--selector] 
    [<URI> | <PACKAGE> | <COMPONENT>] 

回答

3

您可以使用URI格式提供<INTENT>am broadcastam startservice

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

URI格式supports以下extra類型:

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

是有可能使用startactivity代替廣播那樣? adb shell am startservice -a com.something.test.START -e len 5.這樣做會導致無效的從字符串轉換爲double – laggyluk