此篇起源:在开发中需要跳转到WIFI列表,因是自定Lancher - 跳转之后发现无法返回当前APP,针对于此,在总结Wifi跳转的同时一起总结了系统自带的功能跳转 ~
今年开始写售货机的项目(自定Lancher),有点像物联网 - - ~ 但具体是不是呢?那我也就不太清楚咯…
我还是从前那个少年 > <
效果
尾部Demo的实现效果 ~
系统设置
action | 界面 |
---|---|
ACTION_SETTINGS | 系统设置界面 |
ACTION_APN_SETTINGS | APN设置界面 |
ACTION_LOCATION_SOURCE_SETTINGS | 定位设置界面 |
ACTION_AIRPLANE_MODE_SETTINGS | 更多连接方式设置界面 |
ACTION_DATA_ROAMING_SETTINGS | 双卡和移动网络设置界面 |
ACTION_ACCESSIBILITY_SETTINGS | 无障碍设置界面/辅助功能界面 |
ACTION_SYNC_SETTINGS | 同步设置界面 |
ACTION_ADD_ACCOUNT | 添加账户界面 |
ACTION_NETWORK_OPERATOR_SETTINGS | 选取运营商的界面 |
ACTION_SECURITY_SETTINGS | 安全设置界面 |
ACTION_PRIVACY_SETTINGS | 备份重置设置界面 |
ACTION_VPN_SETTINGS | VPN设置界面,可能不存在 |
ACTION_WIFI_SETTINGS | 无线网设置界面 |
ACTION_WIFI_IP_SETTINGS | WIFI的IP设置 |
ACTION_BLUETOOTH_SETTINGS | 蓝牙设置 |
ACTION_CAST_SETTINGS | 投射设置 |
ACTION_DATE_SETTINGS | 日期时间设置 |
ACTION_SOUND_SETTINGS | 声音设置 |
ACTION_DISPLAY_SETTINGS | 显示设置 |
ACTION_LOCALE_SETTINGS | 语言设置 |
ACTION_VOICE_INPUT_SETTINGS | 辅助应用和语音输入设置 |
ACTION_INPUT_METHOD_SETTINGS | 语言和输入法设置 |
ACTION_USER_DICTIONARY_SETTINGS | 个人字典设置界面 |
ACTION_INTERNAL_STORAGE_SETTINGS | 存储空间设置的界面 |
ACTION_SEARCH_SETTINGS | 搜索设置界面 |
ACTION_APPLICATION_DEVELOPMENT_SETTINGS | 开发者选项 |
ACTION_DEVICE_INFO_SETTINGS | 手机状态信息的界面 |
ACTION_DREAM_SETTINGS | 互动屏保设置的界面 |
ACTION_NOTIFICATION_LISTENER_SETTINGS | 通知使用权设置的界面 |
ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS | 勿扰权限设置的界面 |
ACTION_CAPTIONING_SETTINGS | 字幕设置的界面 |
ACTION_PRINT_SETTINGS | 打印设置界面 |
ACTION_BATTERY_SAVER_SETTINGS | 节电助手界面 |
ACTION_HOME_SETTINGS | 主屏幕设置界面 |
ACTION_APPLICATION_DETAILS_SETTINGS | 根据包名跳转到系统自带的应用程序信息 |
ACTION_APPLICATION_SETTINGS | 应用程序列表 |
ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS | 应用程序界面【所有的】 |
ACTION_MANAGE_APPLICATIONS_SETTINGS | 应用程序列表界面【已安装的】 |
ACTION_INPUT_METHOD_SUBTYPE_SETTINGS | 【API 11及以上】语言选择界面 【多国语言选择】 |
ACTION_NFCSHARING_SETTINGS | 显示NFC共享设置【API 14及以上】 |
ACTION_NFC_SETTINGS | 显示NFC设置【API 16及以上】 |
ACTION_QUICK_LAUNCH_SETTINGS | 快速启动设置界面 |
使用方式
常规使用
在对应事件内使用下方代码即可,xxx可根据上方action进行替换
Intent intent = new Intent(Settings.xxx);
startActivity(intent);
跳过
通用:跳转设置的子界面,均有跳回按钮(但是针对跳转设置界面无效)
Bundle bundle = new Bundle();
bundle.putBoolean("extra_prefs_show_skip", true);
bundle.putBoolean("extra_prefs_show_button_bar", true);
bundle.putBoolean("extra_prefs_set_next_text", true);
bundle.putBoolean("extra_prefs_set_back_text", true);
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
intent.putExtras(bundle);
startActivity(intent);
返回
带有返回键的跳转:可用在部分以安卓为主板,自开发APP为Lancher,不带物理或者虚拟按键栏,
但又想使用系统自带的wifi功能模块(但是7.0的系统上依旧有左上角功能栏,可能会让客户跳转到其他地方去)
Intent it = new Intent(Settings.ACTION_WIFI_SETTINGS);
it.putExtra("extra_prefs_show_button_bar", true);
it.putExtra("extra_prefs_set_back_text", "返回");
it.putExtra("extra_prefs_set_next_text", "完成");
startActivity(it);
仅支持WIFI - 返回
注意:WifiManager.ACTION_PICK_WIFI_NETWORK (带有返回键,且只有wifi功能模块的,还可在result中监听)
Intent thatIntent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
thatIntent.putExtra("only_access_points", true);
thatIntent.putExtra("extra_prefs_show_button_bar", true);
thatIntent.putExtra("wifi_enable_next_on_connect", true);
startActivityForResult(thatIntent, 1);
Demo
ManiActivity
package nk.com.settingdemo;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn1).setOnClickListener(this);
findViewById(R.id.btn2).setOnClickListener(this);
findViewById(R.id.btn3).setOnClickListener(this);
findViewById(R.id.btn4).setOnClickListener(this);
findViewById(R.id.btn5).setOnClickListener(this);
findViewById(R.id.btn6).setOnClickListener(this);
findViewById(R.id.btn7).setOnClickListener(this);
findViewById(R.id.btn8).setOnClickListener(this);
//带返回部分
findViewById(R.id.btn9).setOnClickListener(this);
findViewById(R.id.btn10).setOnClickListener(this);
findViewById(R.id.btn11).setOnClickListener(this);
}
/**
* 简单封装一下Intent跳转,懒得多些代码 ...
**/
void toIntent(String action) {
Intent intent = new Intent(action);
startActivity(intent);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn1:
toIntent(Settings.ACTION_SETTINGS);
break;
case R.id.btn2:
toIntent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
break;
case R.id.btn3:
toIntent(Settings.ACTION_WIFI_SETTINGS);
break;
case R.id.btn4:
toIntent(Settings.ACTION_PRINT_SETTINGS);
break;
case R.id.btn5:
toIntent(Settings.ACTION_BLUETOOTH_SETTINGS);
break;
case R.id.btn6:
toIntent(Settings.ACTION_DEVICE_INFO_SETTINGS);
break;
case R.id.btn7:
toIntent(Settings.ACTION_APPLICATION_SETTINGS);
break;
case R.id.btn8:
toIntent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
break;
case R.id.btn9:
//通用:但是针对跳转设置界面无效(可跳转设置的子界面)
Bundle bundle = new Bundle();
bundle.putBoolean("extra_prefs_show_skip", true);
bundle.putBoolean("extra_prefs_show_button_bar", true);
bundle.putBoolean("extra_prefs_set_next_text", true);
bundle.putBoolean("extra_prefs_set_back_text", true);
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
intent.putExtras(bundle);
startActivity(intent);
break;
case R.id.btn10:
//带有返回键的跳转:可用在部分以安卓为主板,自开发APP为Lancher,不带物理或者虚拟按键栏,
//但又想使用系统自带的wifi功能模块(但是7.0的系统上依旧有左上角功能栏,可能会让客户跳转到其他地方去)
Intent it = new Intent(Settings.ACTION_WIFI_SETTINGS);
it.putExtra("extra_prefs_show_button_bar", true);
it.putExtra("extra_prefs_set_back_text", "返回");
it.putExtra("extra_prefs_set_next_text", "完成");
startActivity(it);
break;
case R.id.btn11:
//注意是这个:WifiManager.ACTION_PICK_WIFI_NETWORK (带有返回键,且只有wifi功能模块的,还可以在result中监听)
Intent thatIntent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
thatIntent.putExtra("only_access_points", true);
thatIntent.putExtra("extra_prefs_show_button_bar", true);
thatIntent.putExtra("wifi_enable_next_on_connect", true);
startActivityForResult(thatIntent, 1);
break;
default:
break;
}
}
}
activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 系统设置" />
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 定位设置" />
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 无线网/WIFI设置" />
<Button
android:id="@+id/btn4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 打印设置" />
<Button
android:id="@+id/btn5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 蓝牙设置" />
<Button
android:id="@+id/btn6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 手机状态信息" />
<Button
android:id="@+id/btn7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 应用程序列表" />
<Button
android:id="@+id/btn8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 开发者选项" />
<Button
android:id="@+id/btn9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - WIFI - 跳过" />
<Button
android:id="@+id/btn10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - WIFI - 返回" />
<Button
android:id="@+id/btn11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转 - 仅支持WIFI - 返回" />
</LinearLayout>