28-04-2018, 20:25
package hatirlatici.tubitak.com.hatrlatc;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import java.security.Provider;
public class MuzikOynatici extends Service {
MediaPlayer sarki;
int baslat;
boolean calisiyorsa;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int baslat) {
Log.i("LocalService", "Received start id " + baslat + ": " + intent);
String state = intent.getExtras().getString("extra");
Log.e("Zil Sesi ",state);
assert state != null;
switch (state) {
case "Alarm Aktif":
baslat = 1;
break;
case "Alarm Kapandı":
baslat = 0;
Log.e("Başlama ID'si: ",state);
break;
default:
baslat = 0;
break;
}
if(!this.calisiyorsa && baslat == 1) {
sarki = MediaPlayer.create(this, R.raw.muzik);
}
else if (!this.calisiyorsa && baslat == 0){
Log.e("if there was not sound ", " and you want end");
this.calisiyorsa = false;
this.baslat = 0;
}
else if (this.calisiyorsa && baslat == 1){
Log.e("if there is sound ", " and you want start");
this.calisiyorsa = true;
this.baslat = 0;
}
else {
Log.e("if there is sound ", " and you want end");
sarki.stop();
sarki.reset();
this.calisiyorsa = false;
this.baslat = 0;
}
Log.e("if there was not sound ", " and you want start");
Log.e("MyActivity", "In the service");
return START_NOT_STICKY;
};
@Override
public void onDestroy() {
// Tell the user we stopped.
Toast.makeText(this, "on Destroy called", Toast.LENGTH_SHORT).show();
}
}
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import java.security.Provider;
public class MuzikOynatici extends Service {
MediaPlayer sarki;
int baslat;
boolean calisiyorsa;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int baslat) {
Log.i("LocalService", "Received start id " + baslat + ": " + intent);
String state = intent.getExtras().getString("extra");
Log.e("Zil Sesi ",state);
assert state != null;
switch (state) {
case "Alarm Aktif":
baslat = 1;
break;
case "Alarm Kapandı":
baslat = 0;
Log.e("Başlama ID'si: ",state);
break;
default:
baslat = 0;
break;
}
if(!this.calisiyorsa && baslat == 1) {
sarki = MediaPlayer.create(this, R.raw.muzik);
}
else if (!this.calisiyorsa && baslat == 0){
Log.e("if there was not sound ", " and you want end");
this.calisiyorsa = false;
this.baslat = 0;
}
else if (this.calisiyorsa && baslat == 1){
Log.e("if there is sound ", " and you want start");
this.calisiyorsa = true;
this.baslat = 0;
}
else {
Log.e("if there is sound ", " and you want end");
sarki.stop();
sarki.reset();
this.calisiyorsa = false;
this.baslat = 0;
}
Log.e("if there was not sound ", " and you want start");
Log.e("MyActivity", "In the service");
return START_NOT_STICKY;
};
@Override
public void onDestroy() {
// Tell the user we stopped.
Toast.makeText(this, "on Destroy called", Toast.LENGTH_SHORT).show();
}
}