Skip to content

Instantly share code, notes, and snippets.

@Cliabhach
Created September 24, 2019 18:31
Show Gist options
  • Select an option

  • Save Cliabhach/101e86d20b880325f0b9180d70657bd4 to your computer and use it in GitHub Desktop.

Select an option

Save Cliabhach/101e86d20b880325f0b9180d70657bd4 to your computer and use it in GitHub Desktop.
package com.google.android.material.textfield
import android.content.Context
import android.util.AttributeSet
import android.view.ActionMode
import androidx.annotation.AttrRes
/**
* Variant of [TextInputEditText] that does not crash on
* LGE devices in Instant App builds.
*
*
* See [.startActionMode].
*
*
* @author Philip Cohn-Cort
*/
class SaferTextInputEditText(
context: Context,
attrs: AttributeSet? = null,
@AttrRes defStyleAttr: Int = 0
) : TextInputEditText(context, attrs, defStyleAttr) {
override fun startActionMode(callback: ActionMode.Callback, type: Int): ActionMode? {
var mode: ActionMode? = null
try {
mode = super.startActionMode(callback, type)
} catch (ignored: NullPointerException) {
// The crash in question has only been noted on LG phones
// running Android 8+. Its stacktrace will refer to a non-
// standard function TextView::canClipTray, and logcat will
// contain a message similar to the following:
//
// W/BroadcastQueue: Instant App Denial: receiving Intent { act=com.lge.systemservice.core.cliptray.EDITOR_CLIPTRAY flg=0x10 (has extras) } to ProcessRecord{9a1aaf7 3009:com.lge.systemserver/1000} (pid=3000, uid=1000) requires receiver be visible to instant apps due to sender
//
}
return mode
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment