۱۳۹۳/۰۸/۰۸, ۰۵:۳۳ ب.ظ
ممون، خیلی کمک کردید. امیدوارم سایتتان همیشه جزء بهترینها باشد.
من طبق آموزش شما کدها را قرار دادم:
اما eclips برای getSystemService و خط startActivity(new Intent(this.context, screen2.class)); خطا میدهد.
من طبق آموزش شما کدها را قرار دادم:
کد:
public class ConnectionDetector extends TestCase {
private Context context;
public ConnectionDetector (Context context) {
this.context = context;
}
public void ShowAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this.context);
alertDialog.setTitle(R.string.nettitle);
alertDialog.setMessage(R.string.netmessage);
alertDialog.setIcon(R.drawable.ic_launcher);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton(R.string.netyes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
new NetCheck().execute();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton(R.string.netno,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
private class NetCheck extends AsyncTask<String,String,Boolean>
{
/**
* Gets current device state and checks for working internet connection by trying .
**/
@Override
protected Boolean doInBackground(String... args){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
ShowAlertDialog();
return false;
} else
startActivity(new Intent(this.context, screen2.class));
return true;
}
}
}
اما eclips برای getSystemService و خط startActivity(new Intent(this.context, screen2.class)); خطا میدهد.