Android app crash in play store prelaunch report but working in real device

前端 未结 3 1660
执念已碎
执念已碎 2021-02-05 15:04

Not able to track crash in the project, I got this error in play store pre-launch section, it showing on click of EditText, it got the error. but not getting any cr

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 16:08

    Inspired by @smitty1's solution I made this one. I handle it in a custom EditText instead of checking all EditTexts in a view:

    open class MaxLengthEditText : AppCompatAutoCompleteTextView {
    
        constructor(context: Context) : super(context)
        constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
        constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
    
        /*
         * On Android API versions <= 23 the app crashes if a text that is longer than the max length of the EditText
         * is set using an accessibility action. To avoid this we cut the text down to the maximum allowed length.
         */
        override fun performAccessibilityAction(action: Int, arguments: Bundle?): Boolean {
            if (Build.VERSION.SDK_INT <= 23 && action == AccessibilityNodeInfo.ACTION_SET_TEXT) {
                filters.forEach { filter ->
                    if (filter is InputFilter.LengthFilter) {
                        val maxLength = filter.max
                        arguments?.keySet()?.forEach { key ->
                            if (arguments[key] is CharSequence) {
                                val shorterText = 
    arguments.getCharSequence(key)?.subSequence(0, maxLength)
                                setText(shorterText)
                                return true
                            }
                        }
                    }
                }
            }
    
            return super.performAccessibilityAction(action, arguments)
        }
    }
    

提交回复
热议问题