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
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)
}
}