انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
بررسی اتصال به اینترنت در چند اکتیویتی، در برنامه نویسی اندروید

بررسی اتصال به اینترنت در چند اکتیویتی، در برنامه نویسی اندروید

#6
ممون، خیلی کمک کردید. امیدوارم سایتتان همیشه جزء بهترین‌ها باشد.
من طبق آموزش شما کد‌ها را قرار دادم:


کد:
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)); خطا می‌دهد.
پاسخ
 سپاس شده توسط admin


پیام‌های این موضوع
RE: بررسی اتصال به اینترنت در چند اکتیویتی، در برنامه نویسی اندروید - توسط ramtin2080 - ۱۳۹۳/۰۸/۰۸, ۰۵:۳۳ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان