-1

I am creating an intent and adding an extra parameter to it:

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);
}

I get the intent in my BroadcastReceiver, but the "volume" is always null:

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

What am I missing? It has to be something simple. Thanks.

3
  • Are you sure that currentVolume variable is never null? May 4, 2013 at 3:07
  • given just the code that you posted here currentVolume is not instantiated and thus is null so this would be the expected behavior... In fact currentVolume isn't even declared in this code, so this shouldn't even compile. Please post the section of your code where you declare and instantiate currentVolume. A debugging step that you can take is to print it to the log before you add it to the intent, that will tell you for sure what its value is when you add it.
    – FoamyGuy
    May 4, 2013 at 3:08
  • What is data type of currentVolume, int?
    – Sudhee
    May 4, 2013 at 5:38

1 Answer 1

1

Either currentVolume is String and null or it is int in which case, use getIntExtra

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.