FAQ Database Discussion Community

Audio manager nullpointerexception in service

I need help with that, i found one more same question but didnt work for me. Thats my code: import android.app.Service; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.media.AudioManager; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.provider.CallLog; import android.provider.ContactsContract; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; import...

Audio track not working through Bluetooth in Samsung S6

I am recording audio using AudioRecord and playing using AudioTrack. I am recording Fm analog audio stream using this classes and simultaneously passing into Bluetooth router. Its successfully working with Motorola and Samsung S5. But not working with Samsung Galaxy S6. This is the sample code how i am recording...

java.lang.NoSuchMethodException: dispatchMediaKeyEvent [class android.view.KeyEvent]

I'm trying to use media events to play, pause, next, previous music from my android application. When I run it on Samsung s4 (Android version 4.4.2), I can perform all actions. But I'm unable to perform those actions from my Nexus 5 (Android version 5.0.1). I get error while handling...

how to play sound file in single headphone side

I'm currently developing application and i want to control playing sound file on different headphones sides ex the first time on the left side and second time on the right side is there any way to achieve this ?

How to set speaker phone off when the app is killed by the “Recent App drawer”

I implemented an app which has a button speaker, which is manually set "on" by myAudioManager.setSpeakerphoneOn(true) and "off" vice-versa. But the bug is when you close the application while the speaker is on, it forgets the speaker was on. The next time, the speaker remains on and the call is...

Read out Alarm volume

I try to read out the Alarm volume the following way, but I always get wrong values. The ringer volume is always correct!! That happens on every Smartphone, HTC, Samsung, Sony and even on the virtual device. What could be the problem? private AudioManager amanager; @Override public void onCreate(Bundle savedInstanceState)...

Why AudioManager.getRingerMode() return only 3 modes?

According to the document, getRingerMode() returns the current ringtone mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE. But there should be 4 modes, right? Sound ON, Vibrate OFF: How can I know that the setting is this one? Sound ON, Vibrate ON: RINGER_MODE_NORMAL Sound OFF, Vibrate OFF: RINGER_MODE_SILENT Sound OFF, Vibrate...

Android : Force audio routing

I would like to change the sound device output in my Android app. I want to use the speaker of the phone when the headset plugged. I've tried to use setSpeakerphoneOn from AudioManager classaudioManager.setSpeakerphoneOn(true); with audioManager.setMode(AudioManager.MODE_IN_CALL); but I don't want to set the MODE_IN_CALL ! I want to stay in...

How to increase the ringer & notification volume programmatically in android

I am trying to enable the ringer normal mode and increase the volume programmatically. AudioManager mobilemode = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); // int streamMaxVolume = mobilemode.getStreamMaxVolume(AudioManager.STREAM_RING); switch (mobilemode.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL); mobilemode.setStreamVolume...

Audio through built-in speakers when earphones are plugged in headphone jack in Android

In my application, there is one Card Reader which uses Audio Jack of devices.Now, my problem is I want to produce sound from built-in speakers when Card Reader is intact in HeadPhone Jack of the device. Here are the codes I have tried: 1) Using Reflection Methods Class audioSystemClass; try...

AudioManager setStreamMute() Null Pointer Exception

I am getting Null Pointer Exception on line 219: amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);. It was not happening before, today i saw it first time, i am using Android 5.0. Code mutes notification sound when activity starts and unmutes when it is destroyed. Code: private AudioManager amanager; @Override protected void onCreate(Bundle savedInstanceState) {...