2

I want to detect when a user is pressing the copy in the action bar, I used the solution suggested here: Solution

public boolean onTextContextMenuItem(int id) {
// Do your thing:
boolean consumed = super.onTextContextMenuItem(id);
// React:
switch (id){
    case android.R.id.cut:
        onTextCut();
        break;
    case android.R.id.paste:
        onTextPaste();
        break;
    case android.R.id.copy:
        onTextCopy();
}
return consumed;

}

But when I try checking it on lollipop it's not working. After some debugging I saw that the id is equal to 50855976(0x3080028) while android.R.id.copy is equal to 16908321(0x1020021). So it make sense that it doesn't work.

But what can cause this? I've also noticed that the values are different for devices having 5.0.1 and 5.0.2 Android.

Thank you very much.

Dor Naim
  • 21
  • 3
  • Check if you can get a resource by identifier name... like this...https://stackoverflow.com/a/16369892/6740698 – Xenolion May 17 '18 at 13:49
  • Can't get it to work, I tried this way: Resources resources = context.getResources(); final int resourceId = resources.getIdentifier("copy", "Integer", context.getPackageName()) – Dor Naim May 21 '18 at 13:18
  • But @Dor what is your case? Why do you want to detect if someone has clicked the copy?? – Xenolion May 21 '18 at 14:00
  • But @Dor what is your case? Why do you want to detect if someone has clicked the copy?? – Xenolion May 21 '18 at 14:01

0 Answers0