因此,如果我禁用 Telegram 应用程序的通知,那么当应用程序处于后台/被杀死时,它就无法通知用户有来电。
但是如果我打开 Telegram 应用程序,它就能接收来电通知,首先我以为它是活动中显示的自定义 UI,但事实并非如此,它也显示在 Android 的系统通知面板中。
我自己的视频/语音通话应用程序如何实现?
ConnectionService
这是否与TelecomManager
实现该目标相关并在没有发布通知许可的情况下显示通知?
我注意到以下异常(Firebase Crashlytics):
Fatal Exception: java.lang.RuntimeException
Failure delivering result ResultInfo{who=null, request=1915322883, result=-1, data=Intent { dat=content:/... flg=0xc3 }} to activity {com..../com....Activity}: java.lang.SecurityException: No persistable permission grants found for UID 10571 and Uri content:/...
Fatal Exception: java.lang.SecurityException
No persistable permission grants found for UID 10434 and Uri content:/...
android.content.ContentResolver.takePersistableUriPermission (ContentResolver.java:2952)
Caused by android.os.RemoteException
Remote stack trace: at com.android.server.uri.UriGrantsManagerService.takePersistableUriPermission(UriGrantsManagerService.java:385) at android.app.IUriGrantsManager$Stub.onTransact(IUriGrantsManager.java:139) at android.os.Binder.execTransactInternal(Binder.java:1375) at android.os.Binder.execTransact(Binder.java:1311)
当应用程序调用时ContentResolver.takePersistableUriPermission
:
val safResultLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { activityResult ->
coroutineScope.launch {
if (activityResult.resultCode == Activity.RESULT_OK) {
val treeUri = activityResult.data?.data
if (treeUri != null) {
context.contentResolver.takePersistableUriPermission(
treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
}
}
}
}
// select a folder
try {
safResultLauncher.launch(Intent.ACTION_OPEN_DOCUMENT_TREE)
} catch (e: Throwable) {
// ...
}
仅适用于三星设备(Android 13-14):
更新
因此,我想由于限制,我们可能会尝试清除当前的持久 uri 授予(当您不需要它时),并在无法为某些存储获取持久 uri 时处理异常:
fun grantPermissionForFolderSaf(
context: Context,
activityResult: ActivityResult,
): Uri? {
if (activityResult.resultCode == Activity.RESULT_OK) {
val treeUri = activityResult.data?.data
if (treeUri != null) {
clearAllPersistedUriPermissions(context)
try {
context.contentResolver.takePersistableUriPermission(
/* uri = */ treeUri,
/* modeFlags = */ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
return treeUri
} catch (e: Throwable) {
// ... explanation for a user to try to select a different storage
}
}
}
return null
}
private fun clearAllPersistedUriPermissions(context: Context) {
try {
val contentResolver = context.contentResolver
for (uriPermission in contentResolver.persistedUriPermissions) {
contentResolver.releasePersistableUriPermission(
/* uri = */ uriPermission.uri,
/* modeFlags = */ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
}
} catch (e: Throwable) {
// just to be safe...
e.printStackTrace()
}
}
请投票给问题跟踪器 https://issuetracker.google.com/issues/330368298
我刚刚通过查看 Firebase Crashlytics 注意到我的应用程序发生了一些崩溃,这似乎与尝试使用SharedPreferences
但由于强制转换异常而无法获得首选项的 Google AdMob 库相关:
代码文字:
Fatal Exception: java.lang.ClassCastException
java.lang.Integer cannot be cast to java.lang.String
android.app.SharedPreferencesImpl.getString (SharedPreferencesImpl.java:302)
com.google.android.gms.ads.internal.scionintegration.a.onSharedPreferenceChanged (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:73)
com.google.android.gms.ads.internal.scionintegration.m.a (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:106)
com.google.android.gms.ads.nonagon.a.s (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:439)
com.google.android.gms.ads.nonagon.a.b (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:5)
com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl.getMobileAdsSettingManager (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:52)
com.google.android.gms.ads.internal.client.bx.bR (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:40)
m.ajn.onTransact (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:21)
android.os.Binder.transact (Binder.java:1173)
obj.gL (:com.google.android.gms@[email protected] (190400-607434947):8)
com.google.android.gms.ads.internal.client.ay.getMobileAdsSettingManager (:com.google.android.gms@[email protected] (190400-607434947):12)
com.google.android.gms.ads.MobileAdsSettingManagerCreatorImpl.getMobileAdsSettingManager (:com.google.android.gms@[email protected] (190400-607434947):42)
com.google.android.gms.ads.internal.client.az.fL (:com.google.android.gms@[email protected] (190400-607434947):40)
obk.onTransact (:com.google.android.gms@[email protected] (190400-607434947):101)
android.os.Binder.transact (Binder.java:1173)
com.google.android.gms.internal.ads.zzavg.zzbh (com.google.android.gms:play-services-ads-base@@22.6.0:1)
com.google.android.gms.ads.internal.client.zzcp.zze (zzcp.java:169)
com.google.android.gms.ads.internal.client.zzeq.zza (zzeq.java:169)
com.google.android.gms.ads.internal.client.zzaq.zzc (com.google.android.gms:play-services-ads-lite@@22.6.0:169)
com.google.android.gms.ads.internal.client.zzax.zzf (com.google.android.gms:play-services-ads-lite@@22.6.0:126)
com.google.android.gms.ads.internal.client.zzax.zzd (com.google.android.gms:play-services-ads-lite@@22.6.0:126)
com.google.android.gms.ads.internal.client.zzej.zzA (com.google.android.gms:play-services-ads-lite@@22.6.0:17)
com.google.android.gms.ads.internal.client.zzej.zzm (zzej.java:53)
com.google.android.gms.ads.MobileAds.initialize (com.google.android.gms:play-services-ads-lite@@22.6.0:53)
com.MY_APP_PACKAGE.ads.AdMob.initAdmob (AdMob.kt:128)
有人有这个问题吗?
我还有其他使用 22.6.0 版本 Admob 的应用程序,我没有注意到它们发生此类崩溃,而对于这个应用程序,它只发生在 6 个用户(约 23 万用户)中,但仍然......为什么会发生这种情况......
更新:
发现其他人也出现同样的问题:https ://groups.google.com/g/google-admob-ads-sdk/c/88UHAaWElsc
更新2:
现在我遇到了更多崩溃,现在它影响了其他应用程序
ps 另外,Admob Dashboard API 今天也关闭了,所以 mb 这是相关的
临时解决方案:如果您为应用程序设置了 Firebase Remote Config 以禁用广告,MobileAds.initialize()
如果您添加了特定参数,这也会阻止调用。不幸的是,就我而言,我只有参数来启用/禁用应用程序屏幕上的广告类型(横幅、插页式广告),但没有参数来阻止加载同意信息(UMP 库)和MobileAds.initialize()
,但我现在会添加它以供将来使用案例...