0

We know that we can add some action buttons to chrome custom tabs. For this we have to create pending intent and then it will be able to be added. Right now I have such action button at toolbar:

val icon = BitmapFactory.decodeResource(resources, android.R.drawable.ic_menu_share)
        val intent = Intent(context, MessageWrite::class.java)
        intent.putExtra("mail_type", 6)
        intent.putExtra("theme", "Заявка для Вашей работы $jobTitle")
        intent.putExtra("body", "")
        intent.putExtra("kind", 6)
        if (companyMail.isNotEmpty()) {
            intent.putExtra("receiver_mail", companyMail)
        }
        intent.putExtra("job_lst_type", 4)
        val pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

        builder.setActionButton(icon, "Write to company", pi)

but I would like to make two things:

  1. Add item to menu, not to toolbar like icon.
  2. Call function when I press on this icon, not moving to another activity. So, how I can do it because as I see I have to use pending intents for making it, but I don't know how to do it with pending intent.
Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36
Andrew
  • 1,947
  • 2
  • 23
  • 61
  • you will have to stick with pending intents because chrome custom tabs are opening the Chrome app in fact, where you can't modify anything. Also with the `PendingIntent` you can not only start the activity, but a service, or broadcast receiver also, so you may want to use broadcastreceiver, and call the required function in it. – Vladyslav Matviienko Jun 26 '19 at 08:34
  • but how I can use this receiver at fragment from which I have opened tabs? – Andrew Jun 26 '19 at 08:36
  • register the receiver in that fragment probably? – Vladyslav Matviienko Jun 26 '19 at 08:36
  • this fragment is placed in container, so, I will have to add receiver to fragment or to activity?and then how to work with it? – Andrew Jun 26 '19 at 08:38
  • you can add it to any of them. If you add it to activity, then you have to call your required method of fragment instance in BroadcastReceiver's `onReceive()` method. If you register it in fragment - you can call the method directly by name – Vladyslav Matviienko Jun 26 '19 at 08:40
  • ok, thank you for your help, if I have some question else, could I write you here? – Andrew Jun 26 '19 at 08:41
  • sure, if you continue in this comments - make sure you mention me with `@`, like @VladyslavMatviienko so I see the notification. Also if you will have some code to show, please edit the question, don;t put the code in comments – Vladyslav Matviienko Jun 26 '19 at 08:43
  • @VladyslavMatviienko, I don't understand how to make what I want. As I got I have to register receiver at fragment but I can't find any tutorial :( – Andrew Jun 26 '19 at 08:58
  • searching for `android register receiver in fragment` will give you the answer. – Vladyslav Matviienko Jun 26 '19 at 09:01
  • I found this question - https://stackoverflow.com/questions/53275423/how-to-send-a-data-from-a-broadcast-receiver-to-fragment, but as I see I have to add intent filter but I won't need it inside my fragment – Andrew Jun 26 '19 at 09:02
  • You need to use intent filter, as that is the only way to show which broadcasts your receiver wants to receive. It does not relate to fragment. – Vladyslav Matviienko Jun 26 '19 at 09:04

0 Answers0