Luka Perazic Luka Perazic - 2 months ago 8
Android Question

Inserting logo image into application

I have been trying and trying whole day yesterday to insert my logo image in my application. But with no luck.
I was using ImageView and I was applying all advices from the Internet and I have builded over 50 APK to test it out, and every time it is a failure.

My image was in drawable-nodpi, drawable-xdpi, drawable-xxdpi, drawable-xxxdpi and in mipmap also etc.
Also, I have tried different formats of image and sizes. My last size of image was 300x408px
On Android Studio image is showing but not on ANY device or tablet.
Here is source code

file main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="0">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/logo"
android:id="@+id/imageView4" />

<Button
android:id="@+id/play"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Pusti" />

<Button
android:id="@+id/stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Zaustavi" />

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/tower"
android:id="@+id/imageView3" />




file MusicAndroidActivity.java

package clever.radio;

import java.io.IOException;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;

import static android.R.attr.id;

public class MusicAndroidActivity extends Activity {

static MediaPlayer mPlayer;
Button buttonPlay;
Button buttonStop;
String url = "http://radioclever.stream:8000/stream";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
});

buttonStop = (Button) findViewById(R.id.stop);
buttonStop.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
}

protected void onDestroy() {
super.onDestroy();
// TODO Auto-generated method stub
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}


file AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="clever.radio"
android:versionCode="1"
android:versionName="1.1" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MusicAndroidActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>




strings.xml

<resources>
<string name="app_name">Radio Clever</string>
</resources>


and dimens.xml

<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

Answer

Try android:src insted of app:srcCompat.