我正在创建一个意图并为其添加一个额外的参数:
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");
}
}
}
我错过了什么?它必须是简单的。谢谢。