我想在Android 4.1或更高版本上以编程方式启用GPS。但它仅限于在4.0以上版本上启用GPS。有没有办法启用它.. ??如果有任何办法,请帮助我......
答案 0 :(得分:1)
您可以查看此代码。它对我有用..
import android.net.Uri;
import android.provider.Settings
private void turnGPSOn()
{
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps"))
{
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);
}
}