Colleagues, maybe someone came across, on the emulator the application works fine, and when I install app-debug.apk on the phone, the buttons do not work in the application, the buttons do not even respond to the finger.
Markup:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="111dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:orientation="horizontal" android:padding="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.017"> Code:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img_play = (ImageButton) findViewById(R.id.img_play); img_play.setEnabled(false); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); new PlayerTask().execute(stream); img_play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (flag) img_play.setImageResource(R.drawable.pause); else img_play.setImageResource(R.drawable.play); flag = !flag; if (started) { started = false; mediaPlayer.pause(); } else { started = true; mediaPlayer.start(); } } }); } Manifesto
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="horoshoe.radio.online"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> After removing img_play.setEnabled(false); On the phone, the application crashes, and on the emulator it continues to work
java.lang.RuntimeException: an error occurred while executing doInBackground () at android.os.AsyncTask $ 3.done (AsyncTask.java.38) at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java;54) at java. util.concurrent.FutureTask.setException (FutureTask.java:223) at java.util.concurrent.FutureTask.run (FutureTask.java:242) at android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:243) at java.util. Caused by: java.lang.IllegalStateException at android.media.MediaPlayer._prepare (Native Method) at android.media.MediaPlayer.prepare (MediaPlayer.java:1188) at horoshoe.radio.online.MainActivity $ PlayerTask.doInBackground (MainActivity. java: 71) at horoshoe.radio.online.MainActivity $ PlayerTask.doInBackground (MainActivity.java:65) at android.os.AsyncTask $ 2.call (AsyncTask.java:304) at java.util.conc urrent.FutureTask.run (FutureTask.java:237)
OnClickListener. What is targetSdkVersion? - Suvitruf ♦