| | |
| | | import PendingIntent from 'android.app.PendingIntent' |
| | | import PowerManager from 'android.os.PowerManager' |
| | | import KeyguardManager from 'android.app.KeyguardManager' |
| | | import AlertDialog from 'android.app.AlertDialog' |
| | | import DialogInterface from 'android.content.DialogInterface' |
| | | |
| | | // 来电通知相关常量 |
| | | const CALL_CHANNEL_ID = 'incoming_call_channel' |
| | |
| | | if (context == null) return |
| | | // 1. 检查悬浮窗权限 (Android 6.0+) |
| | | const noneFloat = Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(context) |
| | | if (noneFloat) { |
| | | uni.showModal({ |
| | | title: '权限提示', |
| | | content: '为了在后台收到来电时能弹出通话界面,请开启“悬浮”权限', |
| | | confirmText: '去设置', |
| | | cancelText: '暂不', |
| | | success(res) { |
| | | if (res.confirm) { |
| | | try { |
| | | // 无权限,跳转到权限设置页面 |
| | | const intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | if (!noneFloat) return |
| | | const activity = UTSAndroid.getUniActivity() |
| | | if (activity == null) return |
| | | AlertDialog.Builder(activity) |
| | | .setTitle('权限提示') |
| | | .setMessage('为了在后台收到来电时能弹出通话界面,请开启"悬浮窗"权限') |
| | | .setPositiveButton('去设置', (_dialog : DialogInterface, _which : Int) => { |
| | | try { |
| | | const intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | }) |
| | | .setNegativeButton('暂不', null) |
| | | .show() |
| | | } |
| | | |
| | | // 跳到后台弹出界面权限页面(应用详情设置) |
| | | export function allowBackgroundPopup() { |
| | | const context = UTSAndroid.getAppContext() |
| | | if (context == null) return |
| | | try { |
| | | const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | const context = UTSAndroid.getAppContext() |
| | | if (context == null) return |
| | | // 后台弹出界面无标准API,用悬浮窗权限作为代理判断(有悬浮窗权限通常也允许后台弹出) |
| | | const nonePermission = Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(context) |
| | | if (!nonePermission) return |
| | | const activity = UTSAndroid.getUniActivity() |
| | | if (activity == null) return |
| | | AlertDialog.Builder(activity) |
| | | .setTitle('权限提示') |
| | | .setMessage('为了在后台收到来电时能弹出通话界面,请开启"后台弹出界面"权限') |
| | | .setPositiveButton('去设置', (_dialog : DialogInterface, _which : Int) => { |
| | | try { |
| | | const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | }) |
| | | .setNegativeButton('暂不', null) |
| | | .show() |
| | | } |
| | | |
| | | // 跳到锁屏显示权限页面(通知设置) |
| | | export function allowLockScreen() { |
| | | const context = UTSAndroid.getAppContext() |
| | | if (context == null) return |
| | | try { |
| | | if (Build.VERSION.SDK_INT >= 26) { |
| | | // Android 8.0+ 跳转到应用通知设置 |
| | | const intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) |
| | | intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } else { |
| | | // 低版本跳转到应用详情 |
| | | const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | const context = UTSAndroid.getAppContext() |
| | | if (context == null) return |
| | | // 锁屏显示依赖通知权限,检查通知是否开启 |
| | | const nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager |
| | | const nonePermission = !nm.areNotificationsEnabled() |
| | | if (!nonePermission) return |
| | | const activity = UTSAndroid.getUniActivity() |
| | | if (activity == null) return |
| | | AlertDialog.Builder(activity) |
| | | .setTitle('权限提示') |
| | | .setMessage('为了在锁屏时能显示来电通知,请开启"锁屏显示通知"权限') |
| | | .setPositiveButton('去设置', (_dialog : DialogInterface, _which : Int) => { |
| | | try { |
| | | if (Build.VERSION.SDK_INT >= 26) { |
| | | // Android 8.0+ 跳转到应用通知设置 |
| | | const intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) |
| | | intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } else { |
| | | // 低版本跳转到应用详情 |
| | | const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| | | intent.setData(android.net.Uri.parse('package:' + context.getPackageName())) |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| | | context.startActivity(intent) |
| | | } |
| | | } catch (e) { |
| | | console.error(e) |
| | | } |
| | | }) |
| | | .setNegativeButton('暂不', null) |
| | | .show() |
| | | } |
| | | |
| | | /** |