boptula يوللانغان ۋاقتى 2014-11-28 21:53:58

يانفۇننىڭ تورغا ئۇلانغان ئۇلانمىغانلىقىنى تەكشۈرۈش(java كودى)

بۇ يازمىنى ئاخىرىدا   boptula تەھرىرلىگەن. ۋاقتى2014-11-28 22:22

ئەسسالامۇ ئەليكۇم !
جاۋاكودى

connect.Java   كودى



package com.connect;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Connect extends Activity {
       
        Button ok;
       
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      
      ok = (Button)findViewById(R.id.ok);
      
      ok.setOnClickListener(new OnClickListener(){

                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                NetWorkStatus();
                        }
             
      });
    }
   
    private boolean NetWorkStatus() {

           
            ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

            cwjManager.getActiveNetworkInfo();
            boolean netSataus = true;
            if (cwjManager.getActiveNetworkInfo() != null) {
                   
            netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
           
            Toast.makeText(this, "yanfun torgha ulinip boptu", Toast.LENGTH_LONG).show();
           
            }else
            {
            Builder b = new AlertDialog.Builder(this).setTitle("yanfun torgha ulanmighan")
                                                                            .setMessage("yanfun torgha ulan maptu ,torgha ulamsiz ?");
            b.setPositiveButton("ulaymen", new DialogInterface.OnClickListener()
            {       
                          public void onClick(DialogInterface dialog, int whichButton) {
                          Intent mIntent = new Intent("/");
                          ComponentName comp = new ComponentName(
                          "com.android.settings",
                          "com.android.settings.WirelessSettings");
                          mIntent.setComponent(comp);
                          mIntent.setAction("android.intent.action.VIEW");
                          startActivityForResult(mIntent,0);
                          }
                          }).setNeutralButton("yak", new DialogInterface.OnClickListener() {
                                          public void onClick(DialogInterface dialog, int whichButton) {
                                          dialog.cancel();
                                          }
                          }).show();
                          }
               
                          return netSataus;
            }
           
   
   
}

ئاۋال كونۇپكىنى بىر قىممەتكە تەڭ قىلىۋېلىپ ئاندىن كونۇپكىنىڭ چىكىلىش ھادىسىسىگەبۇ كودنى يازىمىز ئاندىن

@Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                NetWorkStatus();
                        }

ئاندىن ئۇ كود نىڭ ئاستىغا بۇنى
private boolean NetWorkStatus() {

           
            ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

            cwjManager.getActiveNetworkInfo();
            boolean netSataus = true;
            if (cwjManager.getActiveNetworkInfo() != null) {
                   
            netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
           
            Toast.makeText(this, "yanfun torgha ulinip boptu", Toast.LENGTH_LONG).show();
           
            }else
            {
            Builder b = new AlertDialog.Builder(this).setTitle("yanfun torgha ulanmighan")
                                                                            .setMessage("yanfun torgha ulan maptu ,torgha ulamsiz ?");
            b.setPositiveButton("ulaymen", new DialogInterface.OnClickListener()
            {       
                          public void onClick(DialogInterface dialog, int whichButton) {
                          Intent mIntent = new Intent("/");
                          ComponentName comp = new ComponentName(
                          "com.android.settings",
                          "com.android.settings.WirelessSettings");
                          mIntent.setComponent(comp);
                          mIntent.setAction("android.intent.action.VIEW");
                          startActivityForResult(mIntent,0);
                          }
                          }).setNeutralButton("yak", new DialogInterface.OnClickListener() {
                                          public void onClick(DialogInterface dialog, int whichButton) {
                                          dialog.cancel();
                                          }
                          }).show();
                          }
               
                          return netSataus;
            }



AndroidMainfest.xml   كودى


    package="com.connect"
    android:versionCode="1"
    android:versionName="1.0" >

   

          android:icon="@drawable/ic_launcher"
      android:label="@string/app_name" >
                   android:label="@string/app_name"
            android:name=".Connect" >
            
               

               
            

      
   
   
      



بۇ كود تىكى مۇھىم يېرى ئاۋۇ ئاستىدىكى ھوقۇقى :



ئاخىردا

كورۈنمە يۈزى كودى

main.xml كودى

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

          android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/hello" />
   
: يانفۇننىڭ تورغا ئۇلانغان ئۇلانمىغانلىقىنى تەكشۈرۈش(java كودى)