起源:在開發中需要跳轉到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
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>