小编Sas*_*ata的帖子

默认显示的吸气剂:显示!已弃用。在 Java 中已弃用

我需要屏幕的宽度。但最近发现 Android 已defaultDisplay弃用消息:

默认显示的吸气剂:显示!已弃用。在 Java 中已弃用

代码:

val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics.heightPixels

Run Code Online (Sandbox Code Playgroud)

请提出一个替代方案。

android android-layout kotlin

24
推荐指数
5
解决办法
1万
查看次数

不推荐使用“ FragmentStatePagerAdapter(androidx.fragment.app.FragmentManager)”

最近androidx.fragment.app.FragmentManager不推荐使用,并且没有适当的解决方案。

尝试实施支持V4,但无法使用AndroidX。它显示未找到库。

PagerAdapter:

public ViewPagerAdapter(FragmentManager manager) {
    super(manager);
    //...
}
Run Code Online (Sandbox Code Playgroud)

提前致谢。

java android android-fragments

6
推荐指数
2
解决办法
2961
查看次数

Kotlin MediaType.parse("something") 是一个错误。移至扩展功能

尝试为 OkHttp3 创建 JSON 类型标头

val JSONtype = MediaType.parse("application/json; charset=utf-8")

但是出现以下错误:

使用 'parse(String):MediaType?' 是一个错误。移至扩展功能

显示的解决方案/建议:

val JSONType = "application/json; charset=utf-8".toMediaTypeOrNull()

是否服务于相同的操作或要求?

android kotlin okhttp

5
推荐指数
3
解决办法
2914
查看次数

当应用程序未运行时,FCM 显示默认消息而不是自定义消息

问题:我的 FCM 代码针对不同情况显示不同的消息:

案例 1:当应用程序运行时,它显示自定义通知正文

案例 2:当应用程序在后台运行时,它显示自定义通知正文

情况 3:当应用程序未运行时,它显示从 FCM 收到的默认消息而不是自定义消息

代码:

/* The class extends FirebaseMessagingService() */

override fun onMessageReceived(remoteMessage: RemoteMessage) {
        try {
/* Some other codes */            

            val pendingIntent = PendingIntent.getActivity(this, 0, Intent(), PendingIntent.FLAG_ONE_SHOT)
            val builder = NotificationCompat.Builder(this, "" + R.string.notification_channel_id)
                    .setSmallIcon(R.mipmap.ic_launcher_round)
                    .setContentTitle(remoteMessage.notification!!.title)
                    .setContentText(getString(R.string.custom_message_body))
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent)
            val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                val channel = NotificationChannel("" + R.string.notification_channel_id, "Alert channel", NotificationManager.IMPORTANCE_DEFAULT)
                manager.createNotificationChannel(channel)
            }
            manager.notify(0, builder.build())

/* super.onMessageReceived(remoteMessage) was REMOVED to prevent …
Run Code Online (Sandbox Code Playgroud)

android kotlin firebase-cloud-messaging

0
推荐指数
1
解决办法
1057
查看次数