[Android Q&A, Help & Troubleshooting] djjonastybe:
I have already service up and running. So that is working well. Now I am stuck with startForeground. My notifications dont seem to show so I believe startForeground isnt working as well.

I am developing for API range 10-17

I already tried several tutorials without luck

Is someone willing to help me out?

http://www28.zippyshare.com/v/73408891/file.html

package jonashendrickx.radioplayer.rgrfm;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Binder;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

public class RadioService extends Service implements OnErrorListener {
private final IBinder mBinder = new RadioBinder();
private MediaPlayer mMediaPlayer;

private final String[] mirrors = {
"http://stream.intronic.nl/rgrfm",
"http://shoutcast01.edpnet.net:10210"
};

@Override
public IBinder onBind(Intent arg0) {
return mBinder;
}

@Override
public void onCreate() {
initializeMediaPlayer();
startPlaying();
}

@Override
public void onDestroy() {
stopPlaying();
}

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.stop();
mp.release();
return false;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//Log.i("LocalService", "Received start id " + startId + ": " + intent);
return START_STICKY;
}

private void initializeMediaPlayer() {
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(mirrors[0]);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private void startPlaying() {
try {
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.prepareAsync();
} catch (IllegalStateException ex) {
ex.printStackTrace();
return;
}
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
}
});
}

private void stopPlaying() {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
mMediaPlayer.release();
initializeMediaPlayer();
}
}

public class RadioBinder extends Binder {
RadioService getService() {
return RadioService.this;
}
}
}

package jonashendrickx.radioplayer.rgrfm;

import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnClickListener {
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
mRadioService = ((RadioService.RadioBinder)service).getService();
}
@Override
public void onServiceDisconnected(ComponentName className) {
mRadioService = null;
mToggleButtonMediaPlayer.setChecked(false);
}
};
private RadioService mRadioService;
private boolean mIsBound;
private ToggleButton mToggleButtonMediaPlayer;

@Override
public void onClick(View view) {
if (view.equals(mToggleButtonMediaPlayer)) {
if (mRadioService == null) {
doBindService();
} else {
doUnbindService();
}
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToggleButtonMediaPlayer = (ToggleButton)findViewById(R.id.toggleButtonMediaPlayer);
mToggleButtonMediaPlayer.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return false;
}

@Override
protected void onDestroy() {
super.onDestroy();
}

void doBindService() {
bindService(new Intent(this, RadioService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}

void doUnbindService() {
if (mIsBound) {
unbindService(mConnection);
mIsBound = false;
}
}
}