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?) {

        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.lightColor = Color.GREEN

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

            } else {
                builder = Notification.Builder(this)
                    .setContentText("Test description")
                    .setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_launcher))
            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

Re: Open URL with Push Notification in Android 80 80

Hi Stefan, welcome back !

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

Re: Open URL with Push Notification in Android 80 80

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

Re: Open URL with Push Notification in Android 80 80

Should work fine for me

Be a part of the DaniWeb community

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