user1390816
user1390816

Reputation: 623

IllegalArgumentException: Bad stream type 21

I got sometimes following exception on the playStore. It occures on different devices and also on different Android Versions. I never had such an error during testing and I can't produce that error. What could be the problem with the getStreamVolume?

java.lang.IllegalArgumentException: Bad stream type 21
at android.os.Parcel.readException(Parcel.java:1326)
at android.os.Parcel.readException(Parcel.java:1276)
at android.media.IAudioService$Stub$Proxy.getStreamVolume(IAudioService.java:508)
at android.media.AudioManager.getStreamVolume(AudioManager.java:487)
at de.free.Activity.startStopService(Activity.java:452)
at de.free.Activity.onClick(Activity.java:409)
at android.view.View.performClick(View.java:2506)
at android.widget.CompoundButton.performClick(CompoundButton.java:99)
at android.view.View$PerformClick.run(View.java:9112)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)

Thats the code from the Method startStopService:

private void startStopService() {
    long now = new Date().getTime();

    Intent i = new Intent(this, AppService.class);

    i.putExtra(AppService.VOLUME, volumeBar.getProgress());
    i.putExtra(AppService.RINGER, amanager.getRingerMode());
    i.putExtra(AppService.ACT_VOL, amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_RING)));
    i.putExtra(AppService.VOL_ALM, amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM)));
    i.putExtra(AppService.TIME_NOW, now);

    PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);   

    if((tb_runBG.isChecked())) {        
        alarmManager.cancel(pi);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 *update_time, pi);    
    } else {
        alarmManager.cancel(pi);
        stopService(new Intent(this, AppService.class));    
    }
}

AudioManager at onCreate:

//sets the range between 0 and the max volume
volumeBar.setMax(amanager.getStreamMaxVolume(AudioManager.STREAM_RING));

Upvotes: 1

Views: 1201

Answers (1)

Elltz
Elltz

Reputation: 10859

i think its a Hardware Problem, put your code in a try/catch code

try{
    //sets the range between 0 and the max volume
    volumeBar.setMax(amanager.getStreamMaxVolume(AudioManager.STREAM_RING));
 }catch(IllegalArgumentException e){}

check this

AFAIK - to prevent a crash on your side, as for device restarting that is not your side, so im sorry you can not take care of that, the error is being shifted to Samsung and lG-(Manufacturers). so yeah the device might restart when it should, atleast you will convince the user that its not your fault by putting a try/catch block, but if not the user will put the blame on you, as all started when your app crashed. if you read the post actually the solution was to put a try/catch block or return 0 or anything, so i think that is your best bet.

Hope it helps.

Upvotes: 1

Related Questions