如何在android的开发中打开系统设置界面
来源:互联网 发布:java 获取当月第一天 编辑:程序博客网 时间:2024/05/21 07:47
在android的开发中,经常要用到的一个功能就是,打开系统的设置界面,进行诸如wifi,gps等设置。百度地图就是这样一个例子。你打开百度百度地图的app时,系统会检测你是否开启了,wifi,gps等。如果没有开启,它就会弹出一个对话框,问你是否要打开gps,wifi。你点击确定的话。app就会跳转到wifi的设置界面或gps的设置界面。我们今天来实现的就是类似的功能。
开发环境:ubuntu 12.04lts
IDE:eclipse 4.2
android:4.0
真机测试:coolpad 8150d
android api14 参考资料:点击打开链接
布局文件代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btn_setting" android:layout_width="261dp" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_gravity="center" android:text="设置" /> <Button android:id="@+id/btn_wifi_setting" android:layout_width="261dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="WLAN" /> <Button android:id="@+id/btn_location_setting" android:layout_width="261dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="位置服务" /></LinearLayout>
Activity代码:
package com.app.callsystemsetting;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private Button btn_location_setting;private Button btn_wifi_setting;private Button btn_setting;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn_location_setting = (Button) findViewById(R.id.btn_location_setting);btn_wifi_setting = (Button) findViewById(R.id.btn_wifi_setting);btn_setting = (Button) findViewById(R.id.btn_setting);/* * 打开位置服务界面 */btn_location_setting.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubstartActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),0);}});/* * 打开WLAN设置界面 */btn_wifi_setting.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS),0);startActivityForResult(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS),0);}});/* * 打开设置界面 */btn_setting.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubstartActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS),0);}});}}
0 0
- 如何在android的开发中打开系统设置界面
- Android开发_打开系统设置界面
- android代码中打开系统设置界面
- android代码中打开系统设置界面
- android代码中打开系统设置界面
- android代码中打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android 打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- Android打开系统设置界面
- java正则表达式基本符号
- centos维护记录
- JavaScript中的apply()方法和call()方法使用
- ibatis 链接MSSQL2008 的一些问题总结
- Windows下使用第三方lua库
- 如何在android的开发中打开系统设置界面
- varnish 使用rpm文件安装
- js前台编码,asp.net后台解码 防止前台传值到后台为乱码
- leetcode Merge Sorted Array合并两排序数组
- MySQL表与数据向Oracle移植(使用Oracle SQL Developer工具)
- hd1000
- mysql数据库 sql语句优化 避免不必要的开销 提高数据库性能
- HDMI 、分量、CVBS、VGA
- python字符串倒排