Skip to content

Instantly share code, notes, and snippets.

@abhinav272
Created September 17, 2018 10:34
Show Gist options
  • Save abhinav272/d0456405623761aff3f40d8260fd607f to your computer and use it in GitHub Desktop.
Save abhinav272/d0456405623761aff3f40d8260fd607f to your computer and use it in GitHub Desktop.
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.provider.Settings;
import android.view.inputmethod.InputMethodManager;
public class AppUtils {
public static void hideKeyboard(Activity context) {
try {
InputMethodManager inputManager = (InputMethodManager) context.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(context.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void showKeyboard(Activity context) {
try {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(context.getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressLint("HardwareIds")
public static String getUniqueDeviceId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment