Chi*_*han 27 java gps android android-1.5-cupcake
我目前正在Android中编写一个与GPS配合使用的应用程序.目前我能够确定GPS是否已启用.我的问题是,如果禁用,我想在应用启动时启用GPS.我怎么能这样做程序化?
Com*_*are 51
你不能,从Android 1.5开始.您可以做的最多就是弹出活动以允许用户打开/关闭它.使用保留的操作android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
来制作Intent以打开此活动.
TS.*_*.xy 15
if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ))
{
Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
startActivity(myIntent);
}
Run Code Online (Sandbox Code Playgroud)
这个方法代码可以帮到你
private void turnGPSOnOff(){
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);
//Toast.makeText(this, "Your GPS is Enabled",Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
55105 次 |
最近记录: |