Hey all long time no see!! As i started Internet Marketing i quited to code but somehow everything is about coding... :D
So i am trying to come up with new method but i will talk about that in the next thread :)
so I am trying to create push notification and when i click on it to open an URL in a browser, i am using PendingIntent but i have truble doing that.
Here is the code i have

class MainActivity : AppCompatActivity() {

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

        lateinit var notificationManager : NotificationManager
        lateinit var notificationChannel : NotificationChannel
        lateinit var builder : Notification.Builder
        val channelId = "com.example.myapplication"
        val desc = "Test Notification"

        notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        val intent = Intent(this, MainActivity::class.java)
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

        place_order.setOnClickListener {
            //startActivity(Intent(this, AboutMe::class.java))
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                notificationChannel = NotificationChannel(channelId,desc,NotificationManager.IMPORTANCE_HIGH)
                notificationChannel.enableLights(true)
                notificationChannel.lightColor = Color.GREEN
                notificationChannel.enableVibration(true)
                notificationManager.createNotificationChannel(notificationChannel)

                builder = Notification.Builder(this, channelId)
                    .setContentTitle("Test Notification")
                    .setContentText("Testing Notification Text!")
                    .setSmallIcon(R.drawable.ic_launcher_round)
                    .setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_launcher))
                    .setContentIntent(pendingIntent)

            } else {
                builder = Notification.Builder(this)
                    .setContentTitle("Notification")
                    .setContentText("Test description")
                    .setSmallIcon(R.drawable.ic_launcher_round)
                    .setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_launcher))
                    .setContentIntent(pendingIntent)
            }
            notificationManager.notify(1234, builder.build())
        }
    }
}

How do i make when i receive the notification in the notification bar and click it to open browser with custom link?

  • I dont want to use firebase for this, i hope there is a method with intents

Thanks, really appreciate it

Recommended Answers

All 3 Replies

Hi Stefan, welcome back !

What is your status now? Have you received push notification ?

Did you check your code? is it correct? Because I don't see any bugs.

Should work fine for me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.