2012-01-30 88 views
0

我想開始我的活動時,我的wifi將被打開,以便我在WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION時調用我的活動。這將是工作的罰款與2.3(薑餅),三星自來水,但相同的程序將無法在3.1(蜂窩)三星tap.guide工作,爲什麼這種類型的問題將在這裏發生的事情是我的洞代碼:android wifi api問題與3.1

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.net.ConnectivityManager; 
import android.net.wifi.WifiManager; 
import android.util.Log; 

/** 
* A BroadcastReceiver that listens for updates for the 
* ExampleAppWidgetProvider. This BroadcastReceiver starts off disabled, and we 
* only enable it when there is a widget instance created, in order to only 
* receive notifications when we need them. 
*/ 
public class WIFIBroadcastReceiver extends BroadcastReceiver { 

    public static String packageName = "com.example.wifi"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     final String action = intent.getAction(); 

     if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { 
      if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, 
        false)) { 
       Log.d(packageName, "WIFI Connected"); 
       if (context != null) { 

        Intent ssIntent = new Intent(context, 
          com.example.wifi.Activity.class); 
        ssIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        context.startActivity(ssIntent); 
       } 
      } else { 
       Log.d(packageName, "WIFI Connection was Lost"); 
      } 
     } 
    } 
} 

回答

2

我'確切地說,你的問題是,但它聽起來像它與你的ROM有關,如果它的根源與否,等等。

另一種可能性是你正在使用的API。 HC是否需要與GB不同的版本?

我不認爲這是你的代碼,所以如果你無法弄清楚,試着提供有關標籤和手機之間的區別(除了明顯的)之外的信息。

只是一個預感,所以我很抱歉,如果它的基地。

祝你好運!

0

不確定您遇到的問題。將謙卑地建議嘗試替代方案:

您可以註冊WIFI_STATE_CHANGED_ACTION意圖,然後在onReceive(),調用getConnectionInfo()。 NetworkInfo.DetailedState類應該提供(更詳細的)有關是否可以使用IP地址的信息,然後可以開始您的活動。