简体   繁体   中英

developer warning for package android studio

I tried to add Notification to my app and when i wrote the following code:

it show this: [1]: https://i.stack.imgur.com/RxZQ1.png [the Message it show when i click the Button, i don't know if its a Toast message][1]

 package com.example.notifsimple

import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.app.NotificationCompat
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    val id = 1234

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        btnNotif.setOnClickListener{

            val notification = NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.android)
                .setContentTitle("New Animal")
                .setContentText("a new ")
                .build()


            val mNotificationCompat = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

            mNotificationCompat.notify(id, notification)

        }

    }
}

'''`

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btnNotif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Notification"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Thanks for reading my Question. <3

Looking at the platform source , this toast is shown when the notification channel comes out as null.

Looking at your source, there is no notification channel. Starting from Android 8.0 (API 26), all notifications must be assigned to a channel. See the documentation for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM