android 相关问题

Android是谷歌的移动操作系统,用于编程或开发数字设备(智能手机,平板电脑,汽车,电视,磨损,玻璃,物联网)。对于与Android相关的主题,请使用特定于Android的标签,如android-intent,android-activity,android-adapter等。对于开发或编程以外的问题,但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

在 Android studio 中发现重复类错误。(androidx.core:core:x.x.x)

我的应用程序工作正常,但我尝试重建我的应用程序,但我不断收到这些错误 在模块 core-1.13.0.aar -> core-1 中发现重复的类 android.support.v4.app.INotificationSideChannel ....

回答 1 投票 0

Flutter Listview 在使用 FutureBuilder 加载缩略图时冻结

我正在flutter中创建一个文件管理器用于学习目的。我刚刚开始学习flutter,所以对此了解不多。 我的问题是我想显示图像的缩略图...

回答 2 投票 0

在模块 jetified-firebase-iid-20.1.5-runtime 中发现重复的 class.com.firebase.iid.FirebaseInstanceIdReceiver

在模块 jetified-firebase-iid-20.1.5-runtime (com.google.firebase-iid:20.1.5) 和 jetified-firebase-messaging-23.1.1 中发现重复的 class.com.firebase.iid.FirebaseInstanceIdReceiver -运行时(com.

回答 2 投票 0

FOREGROUND_SERVICE_SPECIAL_USE 需要运行时检查

我正在使用前台服务,并根据 Google 指南针对 Android 14 进行更新。 在大多数 Android 14 设备上,这工作正常,但在某些设备上,我遇到以下异常 我就是

回答 1 投票 0

如何从 Android 15 Beta 安装 Android SDK 扩展?

我想测试 Android 15 Beta 中包含的新功能 此功能在文档中标记如下: 添加到 API 级别 35 也在 S 扩展 13 中 我想安装这个扩展...

回答 1 投票 0

如何在 Android JetPack Compose 中使拖动的项目跟随指针位置而无延迟?

我有一个使用 detectorDragGestures 函数的可拖动项目。然而,我注意到,当用户按下屏幕并进行快速移动时,原点之间存在明显的延迟......

回答 2 投票 0

Android compose `NotificationListenerService.onNotificationPosted` 永远不会被调用

我正在尝试向 Kotlin android 撰写项目添加通知侦听器: 我的 AndroidManigest.xml: 我正在尝试向 Kotlin android compose 项目添加通知侦听器: 我的AndroidManigest.xml: <application> <!-- ... --> <service android:name=".MyNotificationListenerService" android:exported="false" android:foregroundServiceType="specialUse" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="explanation_for_special_use" /> </service> </application> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> 我的MainActivity.kt: class MainActivity : ComponentActivity() { private lateinit var serviceIntent: Intent private fun isServiceRunningInForeground(): Boolean { val manager = this.getSystemService(ACTIVITY_SERVICE) as ActivityManager @Suppress("DEPRECATION") for (service in manager.getRunningServices(Int.MAX_VALUE)) { if (MyNotificationListenerService::class.java.name == service.service.className) { if (service.foreground) { return true } } } return false } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) serviceIntent = Intent(this, MyNotificationListenerService::class.java) Log.d("NB", "MainActivity.onCreate") setContent { MyNotificationListenerTheme { var isServiceRunning by remember { mutableStateOf(isServiceRunningInForeground()) } Scaffold( floatingActionButton = { FloatingActionButton( onClick = { if (isServiceRunning) { stopService(serviceIntent) } else { if (!NotificationManagerCompat.getEnabledListenerPackages(this) .contains( packageName ) ) { startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) } startForegroundService( serviceIntent ) } isServiceRunning = !isServiceRunning } ) { Icon( imageVector = if (isServiceRunning) Icons.Default.Close else Icons.Default.PlayArrow, contentDescription = if (isServiceRunning) "Pause" else "Play" ) } } ) { innerPadding -> Surface( modifier = Modifier.padding(innerPadding), color = MaterialTheme.colorScheme.background ) { // Your UI content } } } } } } 我的MyNotificationListenerService.kt: class MyNotificationListenerService : NotificationListenerService() { private val channelId = "MyNotificationListenerService" override fun onCreate() { super.onCreate() createNotificationChannel() startForeground(1, getNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE) Log.d("NB", "MyNotificationListenerService.onCreate") } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Log.d("NB", "MyNotificationListenerService.onStartCommand") return START_STICKY } private fun createNotificationChannel() { val serviceChannel = NotificationChannel( channelId, "My Notification Listener Service Channel", NotificationManager.IMPORTANCE_DEFAULT ) val manager = getSystemService(NotificationManager::class.java) manager.createNotificationChannel(serviceChannel) } private fun getNotification(): Notification { return Notification.Builder(this, channelId) .setContentTitle("Running...") .build() } override fun onBind(intent: Intent?): IBinder? { Log.d("NB", "MyNotificationListenerService.onBind") return super.onBind(intent) } override fun onDestroy() { Log.d("NB", "MyNotificationListenerService.onDestroy") return super.onDestroy() } override fun onNotificationPosted(sbn: StatusBarNotification) { val text = sbn.notification?.extras?.getString("android.text"); Log.d("NB", "MyNotificationListenerService.onNotificationPosted - text: $text") super.onNotificationPosted(sbn) } override fun onNotificationRemoved(sbn: StatusBarNotification) { // Optionally handle notification removal } override fun onListenerConnected() { Log.d("NB", "MyNotificationListenerService.onListenerConnected") } } 当我按“播放”时,我确实收到了日志: MainActivity.onCreate MyNotificationListenerService.onCreate MyNotificationListenerService.onStartCommand 但是当我的手机收到通知时,MyNotificationListenerService.onNotificationPosted没有被呼叫。 我错过了什么? 正如评论中Mike M.所建议的,这不是你自己开始的。 用户必须手动将您的应用程序启用为监听器,然后您的Service将由系统自动启动。 可以将用户引导到屏幕,以便他们使用 startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) 启用它。 删除启动服务的逻辑和所有前台相关代码使其工作: AndroidManifest.xml: <application> <!-- ... --> <service android:name=".MyNotificationListenerService" android:exported="false" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service> </application> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" /> MainActivity.kt: class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyNotificationListenerTheme { var isServiceRunning by remember { mutableStateOf(isServiceRunningInForeground()) } Scaffold { innerPadding -> Surface( modifier = Modifier.padding(innerPadding), color = MaterialTheme.colorScheme.background ) { // Your UI content } } } } } } MyNotificationListenerService.kt: class MyNotificationListenerService : NotificationListenerService() { override fun onCreate() { super.onCreate() Log.d("NB", "MyNotificationListenerService.onCreate") } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Log.d("NB", "MyNotificationListenerService.onStartCommand") return START_STICKY } override fun onBind(intent: Intent?): IBinder? { Log.d("NB", "MyNotificationListenerService.onBind") return super.onBind(intent) } override fun onDestroy() { Log.d("NB", "MyNotificationListenerService.onDestroy") return super.onDestroy() } override fun onNotificationPosted(sbn: StatusBarNotification) { val text = sbn.notification?.extras?.getString("android.text"); Log.d("NB", "MyNotificationListenerService.onNotificationPosted - text: $text") super.onNotificationPosted(sbn) } override fun onNotificationRemoved(sbn: StatusBarNotification) { // Optionally handle notification removal } override fun onListenerConnected() { Log.d("NB", "MyNotificationListenerService.onListenerConnected") } }

回答 1 投票 0

SDK更新33至34

Android 14(API 级别 34)引入了多项改进,包括对广播接收器进行向后不兼容的更改,以提高用户安全性。 Play 核心库使用广播接收器...

回答 1 投票 0

使用颤动相机插件设置自动白平衡(AWB)和其他低级别相机设置的选项

我正在构建一个 flutter 应用程序,它可以录制视频并将其保存到本地文件。录制视频时,我需要设置值/启用/禁用自动白平衡 (AWB)、曝光、ISO 和其他低值

回答 1 投票 0

LeakCanary - destroyView 泄漏 - 这意味着什么?

我在调试应用程序中使用leakCanary,每次我的片段被销毁时,我都会收到泄漏警告。泄漏树首先表示 Fragment 中没有泄漏,只有这部分是泄漏的...

回答 1 投票 0

使用 Koin 进行数据存储的依赖注入

我有一个实现数据存储的 Compose 多平台项目。我使用多平台数据存储作为参考。我在注入数据存储时遇到问题。 常见的主要: 有趣的getDataStore(生产路径:(...

回答 1 投票 0

在 android studio 中将包从 com.example.travelapp 更改为 com.company.travelapp 后,我收到错误:RuntimeException,NoClassDefFoundError

我在 Android 应用程序中遇到与 androidx.lifecycle.ReportFragment$ActivityInitializationListener 相关的 NoClassDefFoundError,导致致命异常,导致应用程序...

回答 1 投票 0

登录 google firebase 帐户时出现错误 16 问题

如您所见,这是我的代码,大部分是从谷歌文档复制的,用于谷歌登录身份验证。问题是,当我单击登录按钮时,它会抛出一个名为“16:”的错误,抱歉

回答 4 投票 0

如何在 TextView 下方制作复选框?

我已经以编程方式创建了 TextView 和复选框。但是当TextView中有不止一行文本时。文字开始互相重叠,附上截图。也在下面我...

回答 1 投票 0

如何通过UUID与简单的蓝牙Ble按钮成功通信

我目前正在开发一个应用程序,需要通过该应用程序在蓝牙按钮(基本上是自拍按钮)和连接的手机之间进行简单的通信。现在,我可以正常连接我的...

回答 1 投票 0

在 Ionic/Capacitor 应用程序上不和谐 OAuth2 身份验证

我正在尝试使用 Ionic 和 Capacitor 编写一个 Web 应用程序/Android 应用程序,允许用户使用 Discord 登录。为此,我使用 Discord API 获取代码,然后使用该代码获取

回答 1 投票 0

SplashScreen之后如何启动MainActivity?

我想在 Android 12 以下的设备上运行我的应用程序。该应用程序将有一个启动屏幕,该应用程序无法使用启动屏幕 api,因为它在 Android 12 以下的设备中无法充分工作。如何

回答 1 投票 0

使用视觉谷歌服务未检测到面部

https://developers.google.com/android/reference/com/google/android/gms/vision/face/FaceDetector.Builder 我在我的应用程序中使用上述谷歌服务进行人脸检测。我确定我的手机有

回答 2 投票 0

ANDROID_HOME 和 ANDROID_SDK_ROOT 环境变量均未导出

我正在从运行 Ubuntu 服务器 20.04 的树莓派 4 运行测试,需要 adb(android sdk 工具)。这些测试已经运行了几个月,没有出现任何问题。 昨天测试开始失败......

回答 5 投票 0

Android 使用键盘上的“完成”按钮来单击按钮

好的,在我的应用程序中,我有一个供用户输入数字的字段。我已将该字段设置为仅接受数字。当用户单击该字段时,它会弹出键盘。在键盘上(在 ICS 上)有...

回答 13 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.