size bütün sınıfı gönderiyorum. İlginiz için tekrar teşekkür ederim.
package com.denemeservis;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.R.string;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
public class AnasayfaActivity extends Activity implements
OnCheckedChangeListener, OnSeekBarChangeListener {
private Button digerRadyo;
private Button mesajGonder;
private Button kamera;
private ToggleButton playStop;
private AudioManager manager;
private SeekBar ses;
int volume = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anasayfa2);
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
try {
URL[] url = new URL[]{new URL("http://85.95.248.115:8014/")};
new AsyncTaskClass().execute(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("onCreate", "onCreate");
baslasinUI();
if (!networkKontrol()) {
baglantiMesaji();
}
manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
ses.setMax(maxVolume);
ses.setProgress(curVolume);
digerRadyo = (Button) findViewById(R.id.btndigerRadyo);
digerRadyo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent radyo = new Intent("android.intent.action.DigerRadyo");
startActivity(radyo);
}
});
mesajGonder = (Button) findViewById(R.id.btnmesajGonder);
mesajGonder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent radyo = new Intent("android.intent.action.Mesaj");
startActivity(radyo);
}
});
kamera = (Button) findViewById(R.id.btnKamera);
kamera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent radyo = new Intent("android.intent.action.Kamera");
startActivity(radyo);
}
});
}
private void baslasinUI() {
Log.d("UI", "UI");
playStop = (ToggleButton) findViewById(R.id.tglbtnPlayStop);
playStop.setOnCheckedChangeListener(this);
ses = (SeekBar) findViewById(R.id.skbrSes);
ses.setOnSeekBarChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// try {
if (isChecked) {
Log.d("play", "play");
startService(new Intent(this, DinlemeServisi.class));
// Toast.makeText(getApplicationContext(),
// "Açılıyor, Lütfen Bekleyiniz!", Toast.LENGTH_LONG).show();
@SuppressWarnings("unused")
Intent intent = new Intent(getApplicationContext(),AsyncTaskClass.class);
} else {
Log.d("stop", "stop");
stopService(new Intent(this, DinlemeServisi.class));
}
try {
if (DinlemeServisiRahmetFM.class != null) {
stopService(new Intent(this, DinlemeServisiRahmetFM.class));
}
if (DinlemeServisiYurtFM.class != null) {
stopService(new Intent(this, DinlemeServisiYurtFM.class));
}
if (DinlemeServisiRisaleFM.class != null) {
stopService(new Intent(this, DinlemeServisiRisaleFM.class));
}
if (DinlemeServisiIrsadFM.class != null) {
stopService(new Intent(this, DinlemeServisiIrsadFM.class));
}
if (DinlemeServisiHikmetFM.class != null) {
stopService(new Intent(this, DinlemeServisiHikmetFM.class));
} else if (DinlemeServisi.class != null) {
startService(new Intent(this, DinlemeServisi.class));
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
manager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
volume = progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(),
"Ses : " + Integer.toString(volume), Toast.LENGTH_SHORT).show();
}
public boolean networkKontrol() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
protected void baglantiMesaji() {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(
"İnternet Bağlantınıza Ulaşamadık!" + "\n"
+ "Lütfen Bağlantınızı Kontrol Ediniz!")
.setPositiveButton("Tamam",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
System.exit(0);
}
});
final AlertDialog alert = builder.create();
alert.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder backbuilder = new AlertDialog.Builder(this);
backbuilder
.setMessage("Uygulamadan Çıkmak Üzeresiniz!")
.setTitle("ÇIKIŞ")
.setCancelable(false)
.setPositiveButton("Evet",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
AnasayfaActivity.this.finish();
moveTaskToBack(false);
try {
if (DinlemeServisiRahmetFM.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisiRahmetFM.class));
}
if (DinlemeServisiYurtFM.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisiYurtFM.class));
}
if (DinlemeServisiRisaleFM.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisiRisaleFM.class));
}
if (DinlemeServisiIrsadFM.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisiIrsadFM.class));
}
if (DinlemeServisiHikmetFM.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisiHikmetFM.class));
} else if (DinlemeServisi.class != null) {
stopService(new Intent(
getApplicationContext(),
DinlemeServisi.class));
}
} catch (Exception e) {
e.printStackTrace();
}
}
})
.setNegativeButton("Hayır",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
});
AlertDialog alertDialog = backbuilder.create();
alertDialog.show();
}
return super.onKeyDown(keyCode, event);
}
@SuppressWarnings("unused")
private class AsyncTaskClass extends AsyncTask<URL, Void, String> {
String message;
ProgressDialog progressDialog;
public void resfreshTask(String message) {
this.message = message;
this.progressDialog = new ProgressDialog(AnasayfaActivity.this);
}
public void execute(String string, String string2, String string3) {
// TODO Auto-generated method stub
}
@Override
protected void onPreExecute() {
progressDialog.setMessage("Açılıyor, Lütfen Bekleyiniz!");
progressDialog.setIndeterminate(true);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(true);
progressDialog.show();
super.onPreExecute();
}
protected String doInBackground(URL... urls) {
try {
Activity context = null;
@SuppressWarnings({ "static-access", "null" })
ConnectivityManager connectUrl = (ConnectivityManager) context
.getSystemService(context.CONNECTIVITY_SERVICE);
if (connectUrl.getActiveNetworkInfo().isConnectedOrConnecting()) {
URL url = urls[0];
HttpURLConnection urlc = (HttpURLConnection) url
.openConnection();
urlc.setConnectTimeout(4000);
urlc.connect();
if (urlc.getResponseCode() == 200) {
} else {
}
}
} catch (Exception e) {
e.printStackTrace();
}
// ozelfmControl(context);
return null;
}
@Override
protected void onPostExecute(String result) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog.setMessage("Radyo Yayınına Şuan Ulaşılamadı!");
}
super.onPostExecute(result);
}
}
/*
* public static boolean ozelfmControl(Context context){ try {
*
* @SuppressWarnings("static-access") ConnectivityManager connectUrl =
* (ConnectivityManager
* )context.getSystemService(context.CONNECTIVITY_SERVICE);
* if(connectUrl.getActiveNetworkInfo().isConnectedOrConnecting()){ URL url
* = new URL("http://85.95.248.115:8014/"); HttpURLConnection urlc =
* (HttpURLConnection)url.openConnection(); urlc.setConnectTimeout(4000);
* urlc.connect();
*
* if(urlc.getResponseCode()==200){ return true; }else{ return false; } } }
* catch (Exception e) { e.printStackTrace(); }
*
* return false;
*
* }
*/
}