[Q] Volume buttons sound, annoying beep how to change it ? - Android Q&A, Help & Troubleshooting

I cant find the answer on whole net, starting to think that it isnt possible.
I have tried adding many variates of volume.mp3 and ogg's to /system/media/ui but it doesnt work, have searched for ogg mp3 wav's and raw files in system files but can't find a think that matches that awful beep sound.
Someone on a forum said that he saw rom with Piano sounds when he was changing volume.
i hope that someone figure it out already
thanks in advance

RE: Volume buttons sound, annoying beep how to change it ?
Here is my code to force volume keys to change media volume (instead of ringer volume) and then change the beep to a click.
Code:
//Volume controls changed to media volume
@Override public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Get audioManager
switch (keyCode) {
case (KeyEvent.KEYCODE_VOLUME_UP):
{
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
return true;
}
case (KeyEvent.KEYCODE_VOLUME_DOWN):
{
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
return true;
}
}
return super.onKeyDown(keyCode, keyEvent);
}
@Override public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
MediaPlayer clickPlayer = MediaPlayer.create(this, R.raw.click);
try {
clickPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
clickPlayer.start();
}
return super.onKeyDown(keyCode, keyEvent);
}

Hi cardinalfib,
thansk for your code - it is exactly what I need.
I'm not an expert - could you tell me how I've to use this code?
What file have I to change?
Thanks a lot!
Tim

Related

[Q] Refer to TTS Object inside inner method.

Well... I am trying to create an application using the TTS Engine.
I can already make it, work, no problem. However I need my buttons to be dinamic, they will come from a database.
**So far you guys have helped me a lot, since now I can do it thanks to the tips I got from you guys.**
**Well.. now I am stuck again.**
Every new button that I create I attach an OnClickListener so it can start the TTS and speak something.
However it's an inner method, so, when I try to run the code below, it gives me a NullPointerException when it tries to "speak" using the TTS. I know the TTS object is out of context, so, **How can I solve this?**
Below the code. It's a little big since I wanted to include everything:
PLEASE JUMP TO THE "HERE IS MY PROBLEM!!!" comment so you guys can see exactly where my problem is. I know where it is, but I don't know how to solve it =(
Any help is appreciatted! =)
Code:
public class LivoxTesteActivity extends Activity implements OnInitListener{
/** Called when the activity is first created. */
private int MY_DATA_CHECK_CODE = 0;
public TextToSpeech tts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
LinearLayout lgeral = new LinearLayout (this);
lgeral.setOrientation(LinearLayout.VERTICAL);
lgeral.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
String array[][] = {{"Comer","eat", "Eu quero comer", "1"},
{"Abraço","hug", "Eu quero um abraço", "2"},
{"Assustado","afraid", "Eu estou com medo", "3"},
{"Beber","drink", "Eu quero beber", "4"}};
int x = array.length;
int qtdeLinhas = 2;
for (int j = 0; j < qtdeLinhas; j++) {
LinearLayout l1 = new LinearLayout (this);
l1.setOrientation(LinearLayout.HORIZONTAL);
l1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
FrameLayout fl;
for (int i = 0; i < array.length; i++) {
fl = (FrameLayout)LayoutInflater.from(getBaseContext()).inflate(R.layout.framelayoutstyle, l1, false);
TextView textoEscrito;
textoEscrito = (TextView)LayoutInflater.from(getBaseContext()).inflate(R.layout.textviewstyle, fl, false);
textoEscrito.setText(array[i][0]);
final String texto = textoEscrito.getText().toString();
final String textoFalar = array[i][2];
ImageButton btn;
btn = (ImageButton)LayoutInflater.from(getBaseContext()).inflate(R.layout.imagebuttonstyle, fl, false);
btn.setImageResource(this.getResources().getIdentifier("drawable/" + array[i][1], null, this.getPackageName()));
btn.setOnClickListener(new Button.OnClickListener(){
public void onClick (View v){
Toast.makeText(getBaseContext(), texto, Toast.LENGTH_SHORT).show();
//*******************************
//HERE IS MY PROBLEM!!!
//*******************************
tts.speak(txtFl, TextToSpeech.QUEUE_ADD, null);
//*******************************
//WHEN I TRY TO RUN THE ABOVE IT GIVES A NULLPOINTEREXCEPTION!!!
//*******************************
}
});
fl.addView(btn);
fl.addView(textoEscrito);
l1.addView(fl);
}
lgeral.addView(l1);
}
setContentView(lgeral);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
tts = new TextToSpeech(this, this);
}
else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
}
else if (status == TextToSpeech.ERROR) {
}
}
@Override
public void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}
By the way... the method Toast.makeText(getBaseContext(), texto, Toast.LENGTH_SHORT).show(); works fine. I believe that's because the Toast is a static class.
So, maybe the solution is to create a static class with the method to speak? Ideas? How can I do it?
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A

(REQ) How to Add Kill Long Press Kill Apps+ Long press volume keys to skip tracks

Does anyone know which jar files and smali files/codes( lines) for adding music control and long press back button to kill apps ?
I need name of files and smali codes.
I need it, too
i think its android-policy.jar or services.jar maybe.
i need it too
AW: (REQ) How to Add Kill Long Press Kill Apps+ Long press volume keys to skip tracks
me too
This is what would be added for Settings:
packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
Code:
packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
public class DevelopmentSettings extends PreferenceActivity
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private static final String KILL_APP_LONGPRESS_BACK = "kill_app_longpress_back";
private CheckBoxPreference mKillAppLongpressBack;
addPreferencesFromResource(R.xml.development_prefs);
mKillAppLongpressBack = (CheckBoxPreference) findPreference(KILL_APP_LONGPRESS_BACK);
}
@Override
protected void onResume() {
super.onResume();
mKillAppLongpressBack.setChecked(Settings.Secure.getInt(getContentResolver(),
Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) != 0);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
} else if (preference == mKillAppLongpressBack) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.KILL_APP_LONGPRESS_BACK,
mKillAppLongpressBack.isChecked() ? 1 : 0);
}
And for frameworks:
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
Code:
Runnable mBackLongPress = new Runnable() {
public void run() {
if (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 0) {
return;
}
try {
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
IActivityManager mgr = ActivityManagerNative.getDefault();
List<RunningAppProcessInfo> apps = mgr.getRunningAppProcesses();
for (RunningAppProcessInfo appInfo : apps) {
int uid = appInfo.uid;
// Make sure it's a foreground USER application
if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID
&& appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
// Kill the entire pid
Toast.makeText(mContext, com.android.internal.R.string.app_killed_message, Toast.LENGTH_SHORT).show();
Process.killProcess(appInfo.pid);
break;
}
}
I SAW IT FROM SAMSUNG PHONE, NOT SURE ABOUT OUR SONY
TELL ME IF IT WORKS
TeamIndia said:
This is what would be added for Settings:
packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
Code:
packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
public class DevelopmentSettings extends PreferenceActivity
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
private static final String KILL_APP_LONGPRESS_BACK = "kill_app_longpress_back";
private CheckBoxPreference mKillAppLongpressBack;
addPreferencesFromResource(R.xml.development_prefs);
mKillAppLongpressBack = (CheckBoxPreference) findPreference(KILL_APP_LONGPRESS_BACK);
}
@Override
protected void onResume() {
super.onResume();
mKillAppLongpressBack.setChecked(Settings.Secure.getInt(getContentResolver(),
Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) != 0);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
} else if (preference == mKillAppLongpressBack) {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.KILL_APP_LONGPRESS_BACK,
mKillAppLongpressBack.isChecked() ? 1 : 0);
}
And for frameworks:
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
Code:
Runnable mBackLongPress = new Runnable() {
public void run() {
if (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 0) {
return;
}
try {
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
IActivityManager mgr = ActivityManagerNative.getDefault();
List<RunningAppProcessInfo> apps = mgr.getRunningAppProcesses();
for (RunningAppProcessInfo appInfo : apps) {
int uid = appInfo.uid;
// Make sure it's a foreground USER application
if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID
&& appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
// Kill the entire pid
Toast.makeText(mContext, com.android.internal.R.string.app_killed_message, Toast.LENGTH_SHORT).show();
Process.killProcess(appInfo.pid);
break;
}
}
I SAW IT FROM SAMSUNG PHONE, NOT SURE ABOUT OUR SONY
TELL ME IF IT WORKS
Click to expand...
Click to collapse
no its completely different...bcz we dont u use kill concept smali...
so we have to mod android.policy.jar
settings.apk
and fw-res.apk..
iam almost making a tut for it...will add it in my tut thread soon..

[TUT]Bind codes to KeyPress

Code:
public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode[COLOR="Cyan"].Back[/COLOR])
{
[COLOR="Red"][B]//code here what happens after Pressing Back button[/B][/COLOR]
return true;
}
return base.OnKeyDown(keyCode, e);
}
Change the button u want Back (The one in blue color)
HAPPY CODING~~~

[Q] Check whether device is rooted or not programmatically?

Hello guys,
I would like to take your best suggestions and help for this issue. I have written function to check whether my device is rooted or not? Actually this function is working properly with other devices excepting Samsung Galaxy S4 MINI and Galaxy S5 rooted device. So we can say it is not working to the level of 100%. So kinldy help me to solve this issue and give your best suggestions with effective solution which can work on all the devices.
My Code is something like below :
Code:
/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
Waiting for your reply guys ASAP,
Thanks

WhatsApp redirects media sharing to sound recorder

I have created an app which shares an audio file to whatsapp when a user holds down a button. All works well, except for the fact that I can no longer share audio files directly from Whatsapp. This behaviour is illustrated below. Audio can be shared by clicking on 'Audio' which should redirect the user to a file like activity where they can select their audio. See ibb (dot) co/WDwfSGq for screenshot (since I can't link images yet *sigh*).
This is, however, not the case. When I click it, WhatsApp redirects me to the audio recorder. From this screen I can record some audio and share that audio, but I cannot browse my files. See ibb (dot) co/12hg1SQ
I suspect the intent defined below has caused this as other users have reported the same issue while others, who did not use this functionality yet, have no problem when sharing audio directly via WhatsApp.
Code:
public boolean onLongClick(View view) {
String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (ContextCompat.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((MainActivity) mContext, new String[]{permission}, 2);
return false;
} else {
// Permission has been granted
try {
String file = "soundboard/" + person + "/" + getItem(getAdapterPosition());
file = copyFiletoExternalStorage(file, getItem(getAdapterPosition()));
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file));
sendIntent.setType("audio/*");
mContext.startActivity(Intent.createChooser(sendIntent, "Send your audio file"));
return true;
} catch (Exception e) {
Toast.makeText(mContext.getApplicationContext(), "Sharing has failed.", Toast.LENGTH_SHORT).show();
return false;
}
}
}
And a helper class to copy the file to sd storage prior to sending the intent. This code has been taken and modified from this comment on stackoverflow: stackoverflow (dot) com/a/46243768/11086911
Code:
private String copyFiletoExternalStorage(String file, String resourceName){
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String pathSDCard = Environment.getExternalStorageDirectory() + "/Android/data/" + mContext.getPackageName() + "/" + resourceName;
try {
InputStream in = mContext.getAssets().open(file);
FileOutputStream out;
out = new FileOutputStream(pathSDCard);
byte[] buff = new byte[1024];
int read;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
out.flush();
} finally {
in.close();
out.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pathSDCard;
}
else
return "";
}
I have already deinstalled my own application, rebooted my phone, and reinstalled WhatsApp but to no avail. What can I do to fix WhatsApp and how do I prevent this from happening again? For reference, I am running a Huawei P10 lite with stock rom Android 8.0 and have made no modifications at all. Though as I said before, this issue has been reported on other phones as well.

Categories

Resources