-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 で意図を取得しますが、「ボリューム」は常に null です。

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 に答える