Last active
July 24, 2024 13:35
-
-
Save bendenoz/d9832f24caa6c826f1c4 to your computer and use it in GitHub Desktop.
Basic class to play system sound without user interaction from adb command line. Must be compiled to .dex file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.media.MediaPlayer; | |
import android.media.AudioManager; | |
import android.util.Log; | |
import java.io.IOException; | |
public class Beep { | |
/** | |
* Command-line entry point. | |
* | |
* @param args The command-line arguments | |
*/ | |
public static void main(String[] args) { | |
(new Beep()).run(args); | |
} | |
private void run(String[] a) { | |
MediaPlayer mp = new MediaPlayer(); | |
try { | |
mp.setDataSource(a[0]); | |
mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); | |
mp.setVolume(1f,1f); | |
mp.prepare(); | |
mp.start(); | |
} | |
catch (IOException e) { | |
Log.w("Beep", "IOException", e); | |
} | |
System.out.print("Playing " + mp.getDuration() + "ms"); | |
int i = 0; | |
while(mp.isPlaying() && i < 20) { | |
System.out.print("."); | |
i++; | |
try { | |
Thread.sleep(1000); | |
} | |
catch(InterruptedException e) { | |
Log.w("Beep", "IOException", e); | |
} | |
} | |
System.out.println(); | |
mp.stop(); | |
mp.release(); | |
System.out.println("Stopped."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export CLASSPATH=./Beep.dex | |
app_process /system/bin Beep /system/media/audio/ringtones/Beep-beep.ogg |
@fogged its working fine on android Q (no root), so yes i guess
@fogged its working fine on android Q (no root), so yes i guess
do you know if is working on Android 12 ?
i get error
I see it playing on Android 9, but no sound comes out.
Any idea what could be wrong?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this method still work on android 7 Nougat or 8 Oreo?