当前位置:  软件>java开源软件 iis7站长之家

android-wifi-connecter

    来源:    发布时间:2015-02-03

    本文导语:  这是一个用来连接到 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.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3