0

I am working on android studio project for the first time and I am using Broadcast Receiver. Whenever I run my application I get an error that my Broadcast File uses or overrides a deprecated Api. Although my project runs fine but I need to know why I am getting this and how to get rid of this error.My broadcast file is as follows:

package com.example.user.offlinemobilefinder;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
public class AlarmActivity extends AppCompatActivity {

MediaPlayer myMediaPlayer = null;
Button btnStop;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarm);

    Intent intent= getIntent();
    final String contact=intent.getStringExtra("contact");

    btnStop=findViewById(R.id.stopButton);

    myMediaPlayer = MediaPlayer.create(this, R.raw.loudalarm);
    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    myMediaPlayer.start();


    btnStop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            myMediaPlayer.stop();

            SmsManager smsManager = SmsManager. getDefault();
            smsManager.sendTextMessage(contact, null, "Alarm Stoped", null, null);
        }
    });
}
}

Thanks in advance for help.

  • 1
    Possible duplicate of [DemoActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details](https://stackoverflow.com/questions/27513833/demoactivity-java-uses-or-overrides-a-deprecated-api-note-recompile-with-xlin) – Dor Oct 10 '19 at 14:09

1 Answers1

0

AndroidStudio should tell you which method is deprecated. You can then go to the documentation for that method on developer.android.com and there should be a note telling you what to use instead.

David Wasser
  • 93,459
  • 16
  • 209
  • 274