开启系统Activity

最后更新于:2022-04-01 14:43:14

下面这个代码首先会检查手机的wifi是否已经连接,如果没有连接就会跳转到系统的设置页面。 我首先在编译器里面通过连接手机查找手机打开设置页面是调用系统的哪个Activity,最后截出来的信息是: 03-01 15:40:54.293: V/ActivityManager(573): ACT-Launching: ActivityRecord{423fb8f8 u0 com.android.settings/.HWSettings} 根据这条信息可以知道设置页面是哪个包和哪个类。代码通俗易懂。。 ~~~ package com.example.mytest; import android.net.wifi.WifiManager; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WifiManager wifiManager = (WifiManager) this .getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled() == true) { Toast.makeText(this, "wifi可用", 0); } else { Toast.makeText(this, "wifi不可用", 0); //03-01 15:40:54.293: V/ActivityManager(573): ACT-Launching: ActivityRecord{423fb8f8 u0 com.android.settings/.HWSettings} Intent intent = new Intent(); intent.setClassName("com.android.settings", "com.android.settings.HWSettings"); startActivity(intent); } } } ~~~
';