kindly post the logcat error here.
On Thu, Nov 17, 2016 at 9:51 PM, Timothy Hopfer <[email protected]>
wrote:
> I made an app that tests the speakers in an HTC phone. it tests both the
> bottom speaker, the top speaker, and the headphones, all while the
> headphones are plugged in. It works perfectly in the HTC Desire Eye that
> is running KitKat 4.4.4, but it does not work correctly on the HTC Desire
> that is running Lollypop 5.1. In the lollypop phone, it only plays from
> the bottom speaker, and if the headphones are plugged in, it goes through
> the headphones instead. I have been looking everywhere but cant find the
> answer. Does anyone know what I should do to make my app work in
> Lollypop? I have included the code in case you see some deprecated code
> that I should update. Also, the app does not crash on Lollypop, just does
> the audiomanager or mediaplayer doesn't work the correctly. Thanks so much.
>
> public class LeftSpeakerActivity extends Activity {
> int default_mode; //Saves the default mode of the device
> int music_volume; //Saves the default volume of the music stream
> int call_volume; //Saves the default volume of the in call stream
> String device_type = null;//Stores the device type
> AudioManager audioManager; //Object to provide access to system
> volume controls and settings
> String model = android.os.Build.MODEL;
> String Manufacturer = android.os.Build.MANUFACTURER;
> boolean isNexus = false;
> TextView title_text;
> MediaPlayer mp;
> //preset volume
> int volume = 10;
> public final static String log_tag = "LeftSpeaker";
>
> Handler mHandler = new Handler();
> /*
> * (non-Javadoc)
> * @see android.app.Activity#onCreate(android.os.Bundle).
> * First function entered when the application is created
> * This function is used to initialize the layout and the device
> type
> * based on the model and device Manufacturer.This function also
> stores
> * the default audio stream value and modes to reset it back to
> these
> * values once we exit the application
> */
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
> /*
> * API's to launch the application when the tablet is locked or
> * display is turned off
> */
> getWindow().addFlags(WindowManager.LayoutParams.
> FLAG_TURN_SCREEN_ON);
> getWindow().addFlags(WindowManager.LayoutParams.
> FLAG_DISMISS_KEYGUARD);
> getWindow().addFlags(WindowManager.LayoutParams.
> FLAG_SHOW_WHEN_LOCKED);
> // setRequestedOrientation(ActivityInfo.SCREEN_
> ORIENTATION_LANDSCAPE);
> setRequestedOrientation(ActivityInfo.SCREEN_
> ORIENTATION_LOCKED);
> setContentView(R.layout.activity_left_speaker);
>
>
> title_text = ((TextView) findViewById(R.id.textView3));
> title_text.setTextColor(Color.RED);
> title_text.setText("LEFT SPEAKER TEST IN PROGRESS" + "\n" +
> "VOLUME IS SET AT" + volume);
> Context mContext = getApplicationContext();
> createTempFile("Status_LeftSpeaker.txt", "INPROGRESS");
>
> audioManager = (AudioManager) getSystemService(Context.
> AUDIO_SERVICE);
> default_mode = audioManager.getMode();
> music_volume = audioManager.getStreamVolume(
> AudioManager.STREAM_MUSIC);
> call_volume = audioManager.getStreamVolume(
> AudioManager.STREAM_VOICE_CALL);
>
> //Setting the volume level
> audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,volume,
> AudioManager.FLAG_SHOW_UI);
> audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
> volume, AudioManager.FLAG_SHOW_UI);
> audioManager.setSpeakerphoneOn(true);
>
> //start_playing();
> playSound(true);
>
> }
> //TRUE PLAYS OVER SPEAKERS
> private void playSound(boolean speakers){
>
> mp = MediaPlayer.create(getApplicationContext(),
> R.raw.tone_right);
> if (speakers){
> mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
>
> }else {
> mp.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
>
> }
> mp.start();
> mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
> {
> @Override
> public void onCompletion(MediaPlayer mp) {
> createTempFile("Status_LeftSpeaker.txt", "COMPLETED");
> exit_function();
> }
> });
> }
>
>
> private void exit_function() {
> onDestroy();
> }
>
> @Override
> /*
> * (non-Javadoc)
> * @see android.app.Activity#onDestroy()
> * Function invoked before we exit the application . Reset all the
> volume
> * and stream values in this function
> */
> protected void onDestroy() {
> Log.i(log_tag,"Entered onDestroy()");
> super.onDestroy();
> //mp.reset();
> if (mp != null) {
> mp.release();
> }
> //Reset to the default settings here
> audioManager.setMode(default_mode);
>
> audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
> music_volume, AudioManager.FLAG_SHOW_UI);
> audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
> call_volume, AudioManager.FLAG_SHOW_UI);
>
> this.finish();
>
> }
>
> /*
> * Function to create the a text file in the application directory
> context. This function
> * takes the file name and the string that is to be written in it
> as the input. This function is invoked
> * to create the Result.txt file.
> */
> private void createTempFile(String filename, String text) {
>
> try {
> FileOutputStream fOut = openFileOutput(filename ,
> MODE_WORLD_READABLE);
> OutputStreamWriter osw = new OutputStreamWriter(fOut);
> osw.write(text);
> osw.flush();
> osw.close();
>
> } catch(IOException e) {
> e.printStackTrace();
> }
>
> }
>
>
> }
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/android-developers/d120db29-97d4-4d6b-a5f6-
> 247d2bd93269%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/d120db29-97d4-4d6b-a5f6-247d2bd93269%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/CABHzXASQry6CM2kZoRedXJ87QRx%3DTFsV5LDG3ukGsE3yDMCnBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.