2012-04-01 103 views
0

在應用程序我有一個BroadcastReceiver爲我的互聯網狀態:Android的廣播接收器的位置

public class InternetStateChange extends BroadcastReceiver { 

private Context context; 

public InternetStateChange() { 
    super();   
} 

public void onReceive(Context context, Intent intent) { 
    this.context = context; 
    InternetState.updateInternetListener(isInternetOn()); 
} 

public boolean isInternetOn() { 
    final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 
    final NetworkInfo internet = connMgr.getActiveNetworkInfo(); 

    if (internet != null && internet.isConnected()) 
     return true; 
    return false;  
} 

} 

是有可能的位置狀態做這樣的事? 我並不意味着要做位置更改。我只是想能夠確定手機是否能夠獲得當前位置(如ther inernet.inConnected()方法)

+0

您的意思是檢測設備是否具有gps硬件並在打開和關閉時進行廣播?同樣,檢測是否存在無線網絡硬件並在打開或關閉時進行廣播? – Mel 2012-04-01 12:42:23

+0

是的,但不僅僅是gps。 GPS或位置服務提供商 – 2012-04-01 13:16:01

回答

0

看看LocationManager,有一個廣播發送時提供者獲取啓用/禁用。還有一種方法可以檢查所有可用的位置提供商以及它們是否已啓用。

+0

你是指getPrividers(true)方法嗎? – 2012-04-01 16:37:32

+0

getProviders(boolean enabledOnly)爲您提供所有提供者的列表,以及isProviderEnabled(String提供者),您可以檢查用戶是否已啓用dem或已禁用。如果用戶更改其中一個提供商,則使用KEY_PROVIDER_ENABLED發送廣播以獲得新配置。 – hoeggi 2012-04-02 08:29:20