I need to implement Latest Image & Gif Keyboard in Android 7.1 Nougat, see below screen shot. Can you any one please explain how can i acheive that. if explain with example is more appreciable. See this Android Doc Image Keyboard Support
Asked
Active
Viewed 2,347 times
4

Magesh Pandian
- 8,789
- 12
- 45
- 60
-
1https://developer.android.com/preview/image-keyboard.html – CommonsWare Nov 23 '16 at 13:17
1 Answers
5
Make a Custom EditText like this
public class GifEditText extends EditText {
public GifEditText(Context context) {
super(context);
}
public GifEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GifEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo,
new String[]{"image/gif"});
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (BuildCompat.isAtLeastNMR1() && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false; // return false if failed
}
}
// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.
return true; // return true if succeeded
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
}
And use like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.test.GifEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test gif" />
</LinearLayout>

Ajay Shrestha
- 2,433
- 1
- 21
- 25
-
sorry but i cannot resolve EditorInfoCompat, InputConnectionCompat and BuildCompat. How to do that? – Mr. 0x50 Feb 19 '17 at 21:56
-
2add compile 'com.android.support:support-v13:25.0.0' to resolve EditorInfoCompat – Rax Feb 28 '17 at 12:27