网上搜了N多的代码,也没有个能用的。恳请大师出山哈!
解决方案 »
- android GridView绑定显示SD卡的图片,怎样使显示的顺序按编号显示呢
- 求一个android留言板,在线等
- 我有一个类继承了ViewGroup(ViewGroup继承View),我如何获取getWindow呢
- 下载PHP服务器的APK文件失败
- android bitmap vm 内存溢出问题
- 关于android的自动化设计以及碰到的难题
- 很奇怪的问题 ,simplecursoradapter listview 显示数据出错(100分)
- android的DatePickerDialog和TimePickerDialog如何禁用长按事件
- 通过uri获取文件路径问题
- 小白问点关于opengesl的问题
- listview 自动 删除一行 导致 getview() 重复执行
- [求助贴】关于类似于微博Listview的使用方法。
public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.ctx.sendBroadcast(intent);
String provider = Settings.Secure.getString(ctx.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"));
this.ctx.sendBroadcast(poke);
}
}
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity { Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//turnGPSOn();
jumptosettings();
}
});
} public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent); String provider = Settings.Secure.getString(this.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"));
this.sendBroadcast(poke);
}
}
public void jumptosettings()
{
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//若GPS未打开,跳转到GPS设置页面
// if (!(locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))){
// startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
// }
startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
}
}另一个方法时跳到 setting 界面 需要添加 access_fine_location权限 我测试过了 都是OK的