修复:Android 13 无法授予通知权限 #255

pull/286/head
pppscn 2 years ago
parent 565795a843
commit 11aead738a

@ -18,6 +18,9 @@ import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.gyf.cactus.ext.cactusUpdateNotification
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.idormy.sms.forwarder.App
import com.idormy.sms.forwarder.R
import com.idormy.sms.forwarder.adapter.WidgetItemAdapter
@ -26,6 +29,7 @@ import com.idormy.sms.forwarder.core.webview.AgentWebActivity
import com.idormy.sms.forwarder.database.AppDatabase
import com.idormy.sms.forwarder.databinding.ActivityMainBinding
import com.idormy.sms.forwarder.fragment.*
import com.idormy.sms.forwarder.service.ForegroundService
import com.idormy.sms.forwarder.utils.*
import com.idormy.sms.forwarder.utils.sdkinit.XUpdateInit
import com.idormy.sms.forwarder.widget.GuideTipsDialog.Companion.showTips
@ -88,6 +92,27 @@ class MainActivity : BaseActivity<ActivityMainBinding?>(),
}
}
}
//检查通知权限是否获取
XXPermissions.with(this)
.permission(Permission.NOTIFICATION_SERVICE)
.permission(Permission.POST_NOTIFICATIONS)
.request(OnPermissionCallback { _, allGranted ->
if (!allGranted) {
XToastUtils.error(R.string.tips_notification)
return@OnPermissionCallback
}
//启动前台服务
if (!ForegroundService.isRunning) {
val intent = Intent(this, ForegroundService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}
})
}
override val isSupportSlideBack: Boolean

@ -434,27 +434,18 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
if (isChecked) {
//检查权限是否获取
XXPermissions.with(this)
// 通知栏监听权限
.permission(Permission.BIND_NOTIFICATION_LISTENER_SERVICE)
// 通知栏权限
.permission(Permission.NOTIFICATION_SERVICE).request(object : OnPermissionCallback {
override fun onGranted(permissions: List<String>, all: Boolean) {
SettingUtils.enableAppNotify = true
sbEnableAppNotify.isChecked = true
CommonUtils.toggleNotificationListenerService(requireContext())
}
override fun onDenied(permissions: List<String>, never: Boolean) {
.request(OnPermissionCallback { _, allGranted ->
if (!allGranted) {
SettingUtils.enableAppNotify = false
sbEnableAppNotify.isChecked = false
XToastUtils.error(R.string.tips_notification_listener)
// 如果是被永久拒绝就跳转到应用权限系统设置页面
MaterialDialog.Builder(context!!).content(R.string.toast_denied_never).positiveText(R.string.lab_yes).negativeText(R.string.lab_no).onPositive { _: MaterialDialog?, _: DialogAction? ->
XXPermissions.startPermissionActivity(
requireContext(), permissions
)
}.show()
return@OnPermissionCallback
}
SettingUtils.enableAppNotify = true
sbEnableAppNotify.isChecked = true
CommonUtils.toggleNotificationListenerService(requireContext())
})
}
}

@ -99,7 +99,7 @@ class CommonUtils private constructor() {
* @return 隐私政策说明
*/
private fun getPrivacyContent(context: Context): SpannableStringBuilder {
return SpannableStringBuilder().append(" ").append(ResUtils.getString(R.string.privacy_content_1)).append(" ").append(ResUtils.getString(R.string.app_name)).append("!\n").append(" ").append(ResUtils.getString(R.string.privacy_content_2)).append(" ").append(ResUtils.getString(R.string.privacy_content_3)).append(getPrivacyLink(context, PRIVACY_URL)).append(ResUtils.getString(R.string.privacy_content_4)).append(" ").append(ResUtils.getString(R.string.privacy_content_5)).append(getPrivacyLink(context, PRIVACY_URL)).append(ResUtils.getString(R.string.privacy_content_6))
return SpannableStringBuilder().append(" ").append(ResUtils.getString(R.string.privacy_content_1)).append(" ").append(ResUtils.getString(R.string.app_name)).append("!\n").append(" ").append(ResUtils.getString(R.string.privacy_content_2)).append(" ").append(ResUtils.getString(R.string.privacy_content_3)).append(getPrivacyLink(context, PRIVACY_URL)).append(ResUtils.getString(R.string.privacy_content_4)).append(" ").append(ResUtils.getString(R.string.privacy_content_5)).append(getPrivacyLink(context, PRIVACY_URL)).append(ResUtils.getString(R.string.privacy_content_6)).append(" ").append(ResUtils.getString(R.string.privacy_content_7))
}
/**

@ -59,7 +59,7 @@
<string name="lab_still_disagree">Still disagree</string>
<string name="title_reminder">Reminder</string>
<string name="content_think_about_it_again">Think about it again</string>
<string name="content_privacy_explain_again">We attach great importance to the protection of your personal information, and promise to protect and process your information strictly in accordance with the \"%s Privacy Policy\". If you do not agree to this policy, unfortunately we will not be able to serve you.</string>
<string name="content_privacy_explain_again">We attach great importance to the protection of your personal information, and promise to protect and process your information strictly in accordance with the \"%s Privacy Policy\". \n\nIf you do not agree to this policy, unfortunately we will not be able to serve you.</string>
<string name="lab_privacy_name">\"%s Privacy Policy\"</string>
<!-- 登录 -->
@ -436,6 +436,7 @@
<string name="user_app">User App</string>
<string name="system_app">System App</string>
<string name="tips_battery_optimization">Please deactivate power optimization for SmsForwarder, in order to keep the App alive!</string>
<string name="tips_notification">Please grant Notification permission, in order to keep the App alive!</string>
<string name="tips_notification_listener">Please grant Notification reading permission to SmsForwarder, before other Apps\'s notification could be forwarded. Forwarding automatically canceled!</string>
<string name="notification_listener_service_enabled">The notification service is enabled</string>
<string name="notification_listener_service_disabled">The notification service is disabled</string>
@ -758,7 +759,8 @@
<string name="privacy_content_3">In order to better protect your rights and comply with relevant regulatory requirements, we will pass "</string>
<string name="privacy_content_4">" Explain to you how we collect, store, protect, use and make your information available externally, and explain your rights.\n</string>
<string name="privacy_content_5">For more details, please check "</string>
<string name="privacy_content_6">" full text.</string>
<string name="privacy_content_6">"full text.\n\n</string>
<string name="privacy_content_7">"Please grant Notification permission, in order to keep the App alive!</string>
<string name="other_login_methods">Other login methods</string>
<string name="request_succeeded">Request succeeded</string>
<string name="request_failed">Request failed: </string>

@ -59,7 +59,7 @@
<string name="lab_still_disagree">仍不同意</string>
<string name="title_reminder">温馨提示</string>
<string name="content_think_about_it_again">要不要再想想</string>
<string name="content_privacy_explain_again">我们非常重视对你个人信息的保护,承诺严格按照《%s隐私权政策》保护及处理你的信息。如果你不同意该政策很遗憾我们将无法为你提供服务</string>
<string name="content_privacy_explain_again">我们非常重视对你个人信息的保护,承诺严格按照《%s隐私权政策》保护及处理你的信息。\n\n如果你不同意该政策,很遗憾我们将无法为你提供服务</string>
<string name="lab_privacy_name">《%s隐私权政策》</string>
<!-- 登录 -->
@ -437,6 +437,7 @@
<string name="user_app">用户应用</string>
<string name="system_app">系统应用</string>
<string name="tips_battery_optimization">请将省电优化设置为无限制(不优化),有利于《短信转发器》保活!</string>
<string name="tips_notification">请先授予发送通知权限,有利于《短信转发器》保活!</string>
<string name="tips_notification_listener">请先授予《短信转发器》通知使用权否则无法转发APP通知已经自动关闭转发!</string>
<string name="notification_listener_service_enabled">通知服务已开启</string>
<string name="notification_listener_service_disabled">通知服务未开启</string>
@ -759,7 +760,8 @@
<string name="privacy_content_3">为了更好地保护你的权益,同时遵守相关监管的要求,我们将通过 </string>
<string name="privacy_content_4"> 向你说明我们会如何收集、存储、保护、使用及对外提供你的信息,并说明你享有的权利。\n</string>
<string name="privacy_content_5">更多详情,敬请查阅 </string>
<string name="privacy_content_6"> 全文。</string>
<string name="privacy_content_6">全文。\n\n</string>
<string name="privacy_content_7">请先授予发送通知权限,有利于《短信转发器》保活!</string>
<string name="other_login_methods">其他登录方式</string>
<string name="request_succeeded">请求成功</string>
<string name="request_failed">请求失败:</string>

Loading…
Cancel
Save