2017-04-18 11 views
1

enter image description here私のアプリケーションからwi-fiに接続してください

私はアウトオブボックス経験アプリケーションを開発中です。私は wi-fiを私のカスタマイズしたアプリケーションから、デバイスwifi setupを使って外に接続しなければなりません。 私はwifiマネージャからWi-Fiネットワークリストを取得しました。

私のアプリケーションから無線LANに接続する方法を教えてください。無線LANに与えられたパスワードを設定する方法

listview.setOnItemClickListener(new OnItemClickListener() 
     { 
      @Override 
      public void onItemClick(AdapterView<?> arg0, View view, 
        int position, long id) { 
        AlertDialog.Builder alert = new AlertDialog.Builder(WifiActivity.this); 
        str_wifi_nt_name = arg0.getItemAtPosition(position).toString(); 
        alert.setTitle(str_wifi_nt_name); 
        LinearLayout layout = new LinearLayout(WifiActivity.this); 
        layout.setOrientation(LinearLayout.VERTICAL); 
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
        params.setMargins(20, 0, 30, 0); 
        wifi_password = new EditText(WifiActivity.this); 
        wifi_password.setHint("wi-fi password"); 
        str_wifi_password=wifi_password.getText().toString(); 
        layout.addView(wifi_password, params); 
        alert.setView(layout); 
        alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
          WifiConfiguration wifiConfig = new WifiConfiguration(); 
          wifiConfig.SSID = String.format("\"%s\"", str_wifi_nt_name); 
          wifiConfig.preSharedKey = String.format("\"%s\"", str_wifi_password); 
         } 
        }); 
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
         } 
        }); 
        alert.show(); 
      } 

     }); 
    } 

uは私をhealpくださいmanager.could。

+0

明確ではないため、正確に必要なものを明確にすることはできますか。 – Johny

+0

1.wifi 2.wifiネットワークを接続する3.私のアプリケーションからWiFiを接続する。 1と2が完了しました。 Wi-Fi接続は、デバイスWi-Fiを使用して私のアプリケーションから行った。私はスクリーンショットを添付しました。 –

答えて

1
Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR"); 
          if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) { 
          resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true); 
           } 
          sendBroadcast(resetIntent); 
関連する問題