java.lang.NullPointerException with Nougat

后端 未结 3 1132
别跟我提以往
别跟我提以往 2020-12-09 10:05

My app has been humming along nicely through various Android versions. I have users running it on Android 4.3, 5.0, 5.1 and 6.0 with no problems. However a user with a S7 Ed

相关标签:
3条回答
  • 2020-12-09 10:35

    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" />
    
    0 讨论(0)
  • 2020-12-09 10:47

    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);
          }
        }
    
    0 讨论(0)
  • 2020-12-09 10:49

    I resolved it by removing

    MyEditText.setMovementMethod(new ScrollingMovementMethod());

    0 讨论(0)
提交回复
热议问题