java.lang.NullPointerException with Nougat

拜拜、爱过 提交于 2019-11-28 07:35:56

I resolved it by removing

MyEditText.setMovementMethod(new ScrollingMovementMethod());

This is how you block the copy paste menu from appearing in any way, shape or form. This bug really drove me crazy, and as with any Samsung bug you know its in their code but you also know they won't fix it any time soon. Anyways, here's wonder wall...

  1. Check if Android.Build.Model.toLowerCase().startsWith('sm-g930'). Do not match the whole string, the last letter is a minor version identifier. I stored this boolean in shouldBlockCopyPaste variable which comes up later.

  2. If it matches you want to block the copy paste menu from showing. This is how you ACTUALLY DO IT!!!

Override these 2 functions, you'll notice my shouldBlockCopyPaste boolean, this is so other devices dont get blocked.

   @Override
   public ActionMode StartActionMode (ActionMode.Callback callback){
      if (shouldBlockCopyPaste) {
        return null;
      } else {
        return super.StartActionMode(callback);
      }
    }

   @Override
   public ActionMode StartActionMode (ActionMode.Callback callback, int type){
      if (shouldBlockCopyPaste) {
        return null;
      } else {
        return super.StartActionMode(callback, type);
      }
    }

I've seen this crash for a while in my app coming from Samsung devices. turned out that a long press on a TextView brought up the copy-paste menu on those devices and the user was even able to paste text over (although its not an EditText component). Ended up disabling all types of interactions in the XML of the culprit TextViews (most importantly longClickable) and the crash wen't away.

 <TextView
...
    android:longClickable="false"
    android:clickable="false"
    android:linksClickable="false" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!