Android进阶之路 - 跳转系统设置所属的功能界面

起源:在开发中需要跳转到WIFI列表,因是自定Lancher - 跳转之后发现无法返回当前APP,针对于此,在总结Wifi跳转的同时一起总结了系统自带的功能跳转 ~

今年开始写售货机的项目(自定Lancher),有点像物联网 - - ~ 但具体是不是呢?那我也就不太清楚咯…

这里主要记录了Android中常见的系统界面与跳转方式,同时针对在跳转设置内对应子界面的不同需求,实现了可返回、跳过、下一步等操作 ~

如果你需要了解设置中Android系统自带的功能,需要在跳转Wifi等子界面的时候返回上级,哦,对了,这里说的是自定Lancher的Android设备,大部分售货机就是自定Lancher,在这样的设备上用常规方法的话,可是没有返回操作的! 好了,如果你确实需要这些帮助,那么就开始阅读把 baby ~

实现效果

尾部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_MEMORY_CARD_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

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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章