| | |
| | | import android.widget.Button |
| | | import androidx.lifecycle.ViewModelProvider |
| | | import androidx.lifecycle.lifecycleScope |
| | | import android.os.Build |
| | | import android.Manifest |
| | | import android.content.Context |
| | | import android.content.pm.PackageManager |
| | | import androidx.activity.result.contract.ActivityResultContracts |
| | | import androidx.core.content.ContextCompat |
| | | |
| | | import com.example.firstapp.databinding.ActivitySettingBinding |
| | | import com.example.firstapp.R |
| | |
| | | ViewModelProvider(this).get(HomeViewModel::class.java) |
| | | } |
| | | private var isFullscreen: Boolean = false |
| | | |
| | | // 添加通知权限请求 |
| | | private val notificationPermissionRequest = |
| | | registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> |
| | | if (isGranted) { |
| | | // 权限已授予,可以发送通知 |
| | | AlertDialog.Builder(this) |
| | | .setTitle("通知权限") |
| | | .setMessage("通知权限已开启,您将能收到重要提醒") |
| | | .setPositiveButton("确定", null) |
| | | .show() |
| | | } else { |
| | | // 权限被拒绝 |
| | | AlertDialog.Builder(this) |
| | | .setTitle("通知权限") |
| | | .setMessage("通知权限被拒绝,应用将无法发送提醒通知。您可以在系统设置中手动开启权限。") |
| | | .setPositiveButton("确定", null) |
| | | .show() |
| | | } |
| | | } |
| | | |
| | | @SuppressLint("ClickableViewAccessibility") |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | |
| | | // }) |
| | | |
| | | |
| | | // 通知权限 |
| | | setupNotificationPermission() |
| | | // 退出登录 |
| | | logout() |
| | | // 账号注销 |
| | |
| | | |
| | | } |
| | | |
| | | private fun setupNotificationPermission() { |
| | | binding.notificationPermission.setOnClickListener { |
| | | // 请求通知权限(在Android 13及以上需要) |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
| | | if (ContextCompat.checkSelfPermission( |
| | | this, |
| | | Manifest.permission.POST_NOTIFICATIONS |
| | | ) != PackageManager.PERMISSION_GRANTED |
| | | ) { |
| | | notificationPermissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS) |
| | | } else { |
| | | // 已经有权限 |
| | | AlertDialog.Builder(this) |
| | | .setTitle("通知权限") |
| | | .setMessage("您已经开启了通知权限") |
| | | .setPositiveButton("确定", null) |
| | | .show() |
| | | } |
| | | } else { |
| | | // Android 13以下版本不需要请求权限 |
| | | AlertDialog.Builder(this) |
| | | .setTitle("通知权限") |
| | | .setMessage("当前系统版本无需单独请求通知权限") |
| | | .setPositiveButton("确定", null) |
| | | .show() |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun aboutCompany(){ |
| | | |
| | | binding.aboutCompany.setOnClickListener { |