-1

我正在创建一个意图并为其添加一个额外的参数:

public void stop(View v) {
    AudioManager am = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
    int currentVolume = am.getStreamVolume(AudioManager.STREAM_RING);
    Intent intent = new Intent();
    intent.setAction(CANCEL_ACTION);
    intent.putExtra("volume", currentVolume);
    sendBroadcast(intent);
}

我在我的 BroadcastReceiver 中得到了意图,但“音量”始终为空:

public void onReceive(Context context, Intent intent) {
    if (intent != null) {
        if (intent.getAction().equals("com.hamm.ringeroff.cancel")) {
            String _volume = intent.getStringExtra("volume");
        }
    }
}

我错过了什么?它必须是简单的。谢谢。

4

1 回答 1

1

currentVolume 是 String 和 null 或者它是 int 在这种情况下,使用 getIntExtra

于 2013-05-04T05:42:54.550 回答