android-wifi-connecter -


MIT
Android
Java

软件简介

这是一个用来连接到 WIFI 热点的库。



简单实用方法:

final Intent intent = new Intent("com.farproc.wifi.connecter.action.CONNECT_OR_EDIT");  
intent.putExtra("com.farproc.wifi.connecter.extra.HOTSPOT", scanResult);  
startActivity(intent);

更完整的例子:

import android.app.Activity;  
import android.content.ActivityNotFoundException;  
import android.content.Intent;  
import android.net.Uri;  
import android.net.wifi.ScanResult;  
import android.widget.Toast;  
...  
...  
private static void launchWifiConnecter(final Activity activity, final ScanResult hotspot) {  
  final Intent intent = new Intent("com.farproc.wifi.connecter.action.CONNECT_OR_EDIT");  
  intent.putExtra("com.farproc.wifi.connecter.extra.HOTSPOT", hotspot);  
  try {  
    activity.startActivity(intent);  
  } catch(ActivityNotFoundException e) {  
    // Wifi Connecter Library is not installed.  
    Toast.makeText(activity, "Wifi Connecter is not installed.", Toast.LENGTH_LONG).show();  
    downloadWifiConnecter(activity);  
  }  
}

private static void downloadWifiConnecter(final Activity activity) {  
  Intent downloadIntent = new Intent(Intent.ACTION_VIEW)  
    .setData(Uri.parse("market://details?id=com.farproc.wifi.connecter"));  
  try {  
    activity.startActivity(downloadIntent);  
    Toast.makeText(activity, "Please install this app.", Toast.LENGTH_LONG).show();  
  } catch (ActivityNotFoundException e) {  
    // Market app is not available in this device.  
    // Show download page of this project.  
    try {  
      downloadIntent.setData(Uri.parse("http://code.google.com/p/android-wifi-connecter/downloads/list"));  
      activity.startActivity(downloadIntent);  
      Toast.makeText(activity, "Please download the apk and install it manully.", Toast.LENGTH_LONG).show();  
    } catch  (ActivityNotFoundException e2) {  
      // Even the Browser app is not available!!!!!  
      // Show a error message!  
      Toast.makeText(activity, "Fatel error! No web browser app in your device!!!", Toast.LENGTH_LONG).show();  
    }  
  }  
}