4

I am creating an application that implements a remote. One of the buttons on the remote turns the volume up and down. I have this button on the remote do something different because adjusting the volume in my application is irrelevant. So, my question is:

Would it be possible to disable the native toast message in either the application itself OR in the firmware for the device. I am building my application into a custom ROM, so I should have full access to toast messages correct?

Thanks everyone! The exact thing I am trying to override

Ethan
  • 1,905
  • 2
  • 21
  • 50
  • I hardly understand your question. you said to override default toast style or volume up/down execution? – Youngjae Apr 06 '16 at 03:19
  • @Youngjae Ideally I would like to override the toast message the pops up to show the change in volume. – Ethan Apr 06 '16 at 16:07
  • @user154248 You can chek [this](http://stackoverflow.com/a/30411107/3967525) and [this](http://stackoverflow.com/a/8991519/3967525) – Soham Apr 12 '16 at 11:51
  • @Soham the second link you sent me may be the answer, but I still have to try it. – Ethan Apr 12 '16 at 13:09
  • What I wonder is: is that volume message a toast at all? – Csaba Toth Apr 18 '16 at 04:41

6 Answers6

2

Take a look at AudioManager->FLAG_SHOW_UI Dont use this flag if you dont want to show native toast. Example with adjustStreamVolume

 AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
 audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, flags); 

EDIT: You can also listen for hard volume button actions

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
        //set Volume without toast flag
    }
    return true;
}
ugur
  • 3,604
  • 3
  • 26
  • 57
  • But wouldn't this override the toast if I was to adjust the volume programatically? I need it to override the toast when the volume button is pushed too – Ethan Apr 15 '16 at 22:31
  • Okay I'll try that soon. Thank you – Ethan Apr 15 '16 at 23:17
1

You said you are building application to a custom ROM, so I suggest you look at: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/media/AudioManager.java#AudioManager.handleKeyDown%28android.view.KeyEvent%2Cint%29

I believe that patching that function in your ROM (empty its body, for example) can rid of all volume toasts.

Daniel
  • 573
  • 6
  • 14
  • Which portion of the ROM would Audio Manager be in? I assume it would be in the `system.img` image but I don't know where it would be – Ethan Apr 18 '16 at 02:19
  • If you compile your ROM from AOSP, it's under platform_frameworks_base/media/java/android/media/AudioManager.java. If you want to patch a ROM, I'll search in framework.jar – Daniel Apr 18 '16 at 04:07
  • Do you know how to de-compile that .jar file? – Ethan Apr 18 '16 at 14:25
  • Baksmali and smali – Daniel Apr 18 '16 at 16:40
  • BTW, which Android version you use? Since Android 5.0 framework.jar doesn't contains code, system "classes" are inside Boot.oat (because of ART). I don't know a tool to decompile and then recompile those files. If you do use new Android version, I'll recommand patch the code of the ROM and not it's output – Daniel Apr 18 '16 at 19:32
0

yeah.. you can customize it

 Toast customToast = new Toast(getBaseContext());
 customToast = Toast.makeText(getBaseContext(), val, Toast.LENGTH_LONG);
 customToast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
 customToast.show();
Nikhil Borad
  • 2,065
  • 16
  • 20
0

To override the toast message the pops can use like this:

Toast mToast = Toast.makeText( this  , "" , Toast.LENGTH_SHORT );
switch(id)

 {
 case 0:
       mToast.setText( "Volume UP" );
       mToast.setGravity(Gravity.TOP | Gravity.TOP, 0, 0);
       mToast.show();
           break;
 case 1:
      mToast.setText( "Stop" );
      mToast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
      mToast.show();
           break;
 case 2:
      mToast.setText( "Volume Down" );
      mToast.setGravity(Gravity.END | Gravity.END, 0, 0);
      mToast.show();
           break;
        } 
  }
}); 
Android007
  • 155
  • 11
  • Wouldn't this result in a blank black oval appearing at the bottom of the screen? And I don't believe this would work because the volume toast appears at the top and is built directly into the system, but I'll give it a try – Ethan Apr 12 '16 at 15:07
0
Toast CustomToast = new Toast(getBaseContext());

CustomToast = Toast.makeText(getBaseContext(), val, Toast.LENGTH_LONG);

CustomToast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);

CustomToast.show();
0

According to discussion on Google group on same here, you can't.

Yes, you can use an accessibility service to detect toasts, but definitely you can not prevent them.

Hope this will make sense.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151