美文网首页
打开 MIUI 电池与电量 APP 相关页面

打开 MIUI 电池与电量 APP 相关页面

作者: Itachi001 | 来源:发表于2024-04-18 13:54 被阅读0次
    package cn.yeby.powerkeeper
    
    import android.content.ComponentName
    import android.content.Intent
    import android.os.Bundle
    import android.view.View
    import android.widget.Button
    import android.widget.TextView
    import androidx.activity.enableEdgeToEdge
    import androidx.appcompat.app.AppCompatActivity
    import androidx.core.view.ViewCompat
    import androidx.core.view.WindowInsetsCompat
    
    class MainActivity : AppCompatActivity(), View.OnClickListener {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            enableEdgeToEdge()
            setContentView(R.layout.activity_main)
            ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
                val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
                v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
                insets
            }
            findViewById<Button>(R.id.btn_application_smart_power_saving).setOnClickListener(this)
            findViewById<Button>(R.id.btn_power_and_performance).setOnClickListener(this)
            findViewById<Button>(R.id.btn_smart_scene_power_saving).setOnClickListener(this)
            findViewById<Button>(R.id.btn_cloud_control_information).setOnClickListener(this)
            findViewById<Button>(R.id.btn_thermal_config).setOnClickListener(this)
            findViewById<Button>(R.id.btn_power_tools_config).setOnClickListener(this)
    
        }
    
        override fun onClick(view: View) {
            val pkg = "com.miui.powerkeeper"
            var cls = ""
            when (view.id) {
                R.id.btn_application_smart_power_saving -> cls = "com.miui.powerkeeper.ui.HiddenAppsContainerManagementActivity"
                R.id.btn_power_and_performance -> cls = "com.miui.powerkeeper.ui.HiddenAppsConfigActivity"
                R.id.btn_smart_scene_power_saving -> cls = "com.miui.powerkeeper.ui.ScenarioPowerSavingActivity"
                R.id.btn_cloud_control_information -> cls = "com.miui.powerkeeper.ui.CloudInfoActivity"
                R.id.btn_thermal_config -> cls = "com.miui.powerkeeper.ui.ThermalConfigActivity"
                R.id.btn_power_tools_config -> cls = "com.miui.powerkeeper.ui.framerate.PowerToolsConfigActivity"
            }
            val componentName = ComponentName(pkg, cls)
            val intent = Intent()
            intent.setComponent(componentName)
            intent.putExtra("package_name", packageName)
            try {
                startActivity(intent)
                findViewById<TextView>(R.id.tv).text = ""
            } catch (e: Exception) {
                findViewById<TextView>(R.id.tv).text = e.toString()
            }
        }
    }
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
        <Button
            android:id="@+id/btn_application_smart_power_saving"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="应用智能省电" />
    
        <Button
            android:id="@+id/btn_power_and_performance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电量和性能" />
    
        <Button
            android:id="@+id/btn_smart_scene_power_saving"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="智能场景省电" />
    
        <Button
            android:id="@+id/btn_cloud_control_information"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="神隐模式云控信息" />
    
        <Button
            android:id="@+id/btn_thermal_config"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="温控配置" />
    
        <Button
            android:id="@+id/btn_power_tools_config"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电源工具配置" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="10dp">
    
            <TextView
                android:id="@+id/tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </ScrollView>
    
    </LinearLayout>
    

    相关文章

      网友评论

          本文标题:打开 MIUI 电池与电量 APP 相关页面

          本文链接:https://www.haomeiwen.com/subject/rrfrnrtx.html