Soru & Cevap

interneti açmak için ayarlara yönlendirme ...

21.08.2015 - 10:38

Androidde henüz yeniyim.Eğer bu basit bir sorunsa şimdiden mazur görün.Geliştirdiğim uygulamada kullanıcının internet bağlantısı durumuna göre program çalışıyor.Eğer bağlantı yoksa kullanıcıya ayarlara gitmesini ya da offline devam etmesini soran bir alert diyalog oluşturdum.Fakat sorun şu, kullanıcıyı bağlantı ayarlarına nasıl yönlendirmem gerektiğini bilmiyorum. Sitede herhangi bir içerik bulamadım. Yardımcı olabilecek biri var mı ? Kodlar şu şekilde

Teşekkürler

oncreate..

if(isNetworkConnected()!=true){
           Context mContext = this;
           AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
           builder.setIcon(R.mipmap.connectionicon);
           builder.setTitle("\t Connection Status");
           builder.setMessage("Your device is not connected internet.\nClick OK for go to connection setting");
           builder.setCancelable(false);
           builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                   // opening wifi or mobile data


               }
           });
           builder.setNegativeButton("Countinue Offline", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                   // do nothing

               }
           });

           builder.show();
       }

---

    private boolean isNetworkConnected() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        if (ni==null) {
            // There are no active networks.
            return false;
        } else {
            return true;
        }
    }
6 Görüntülenme

3 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user yd4172
yd4172
06.09.2015 - 05:31

app inventorda nası yapcaz

picture-19121-1442395923.jpg
smtprld
30.08.2015 - 12:37

Tam şu şekilde olmalı kendine göre düzeltirsin bu benim yazdığım bir projeden kod parçası.

@SuppressWarnings("unused")
	public static boolean internetVarMi(String url) {
		if (!url.equals("")) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
			StrictMode.setThreadPolicy(policy);
			HttpGet httpget = new HttpGet("http://"+ url);
			HttpResponse response;
			HttpParams httpParameters = new BasicHttpParams();
			HttpConnectionParams.setConnectionTimeout(httpParameters, 2000);
			HttpConnectionParams.setSoTimeout(httpParameters, 2000);
			HttpClient httpclient = new DefaultHttpClient(httpParameters);
			try {
				response = httpclient.execute(httpget);
				HttpEntity entity = response.getEntity();
				return true;
			} catch (ClientProtocolException e) {
				return false;
			} catch (IOException e) {
				return false;
			}catch (Exception e){
				return false;
			}
		} else {
			return false;
		}
	}

 

picture-19298-1459404577.jpg
alper_beyler
21.08.2015 - 11:37

Merhabalar, bağlantı ayarlarına yönlendirmek için bu kodu kullanmalısın wifi ayarlarına uygulamandan yönlendirmiş olursun kodunda ilgili yere bunu yapıştır dene , kolay gelsin

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

 

 

Muhammed Köse
21.08.2015 - 12:00
teşekkürler Alper bey, işe yaradı :)