3

別のスレッドで GPS を使用して現在の場所を取得する必要があります。

4

3 に答える 3

0
private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

private void turnGPSOff(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(provider.contains("gps")){ //if gps is enabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}
于 2012-05-09T11:51:13.437 に答える
0

GPS は非同期で動作し、別のスレッドで呼び出す必要はありません。GPS は、位置を取得するときにユーザー インターフェイスをフリーズしません。最良の方法は、progressDialog を使用して、位置を取得した後で progressDialog を閉じることです。

于 2012-01-07T16:35:42.600 に答える