Chinaunix首页 | 论坛 | 博客
  • 博客访问: 361070
  • 博文数量: 79
  • 博客积分: 1270
  • 博客等级: 中尉
  • 技术积分: 1370
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-12 08:48
个人简介

freedom~~~~~~~~~~

文章分类

全部博文(79)

文章存档

2014年(10)

2013年(2)

2012年(13)

2011年(54)

分类: Java

2011-05-18 10:19:59

  1. package com.android.factorymode;

  2. import android.app.Activity;
  3. import android.app.ProgressDialog;
  4. import android.content.Context;
  5. import android.net.ConnectivityManager;
  6. import android.net.ethernet.EthernetManager;
  7. import android.net.wifi.WifiManager;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.util.Log;
  11. import android.widget.TextView;

  12. //import com.android.factorymode.eth.EthernetEnabler;

  13. public class EthernetTest extends Activity
  14. {
  15.     EthernetManager ethManager;
  16.     WifiManager wifiManager;
  17.     ConnectivityManager connManager;
  18.     TextView ethState;
  19.     TextView ethIp;
  20.     String mip;
  21.     ProgressDialog myDialog;
  22.     
  23.     private Handler myHandler = new Handler();
  24.     
  25.     private Runnable myRunnable = new Runnable() {
  26.         public void run() {
  27.             for(int i=1;i<=30;i++)
  28.          {
  29.              mip=getIp();
  30.              if(mip.equals(""))
  31.              {
  32.                     try
  33.                     {
  34.                         Log.d("eth2", "---------------geting ip");
  35.                         Thread.sleep(500);
  36.                     }
  37.                     catch (InterruptedException e)
  38.                     {
  39.                         e.printStackTrace();
  40.                     }
  41.              }
  42.              else
  43.              {
  44.                  myHandler.post(updateUI);
  45.                  break;
  46.              }
  47.          }
  48.         }
  49.     };
  50.     
  51.     private Runnable updateUI = new Runnable() {
  52.         public void run() {
  53.             myDialog.cancel();
  54.             ethState.setText(R.string.hasConnect);
  55.          ethIp.setText(mip);
  56.         }
  57.     };
  58.     
  59.     @Override
  60.     protected void onCreate(Bundle savedInstanceState)
  61.     {
  62.         super.onCreate(savedInstanceState);
  63.         setContentView(R.layout.ethernet);
  64.         
  65.      myDialog = new ProgressDialog(this);
  66.      myDialog.setMessage(getString(R.string.gettingip));
  67.      ethState=(TextView)findViewById(R.id.eth_status);
  68.         ethIp=(TextView)findViewById(R.id.eth_ip);
  69.         
  70.         ethManager = (EthernetManager) this.getSystemService(Context.ETHERNET_SERVICE);        
  71.         wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);        
  72.         connManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);

  73.     
  74.     
  75.      wifiManager.setWifiEnabled(false);        
  76.      connManager.setMobileDataEnabled(false);
  77.      ethManager.setEnabled(true);
  78.     
  79.      myDialog.show();

  80.      new Thread(myRunnable).start();
  81.            
  82.      if(mip.equals(""))
  83.      {
  84.          ethState.setText(R.string.noConnect);
  85.          ethIp.setText(" ");
  86.      }
  87.     }
  88.     
  89.     public native String getIp();
  90.     
  91.     
  92.     static
  93.     {
  94.         System.loadLibrary("getIp");
  95.     }
  96. }
阅读(3647) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~