android-wifi-connecter
本文导语: 这是一个用来连接到 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.a...
这是一个用来连接到 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();
}
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。