If you are developing android and using real device to install your build APK instead of virtual device and you are using Xiaomi phone (Mine is Xiaomi Redmi 4x) probably you will facing this error.

To fix this, what you need to do are just enable these configuration in your device.

  • Developer Mode
  • USB Debugging
  • Install via USB
  • USB debugging (Security Settings)


Create Circle ImageView with Picasso

Here is how to create circle ImageView and load the image with picasso library.
First of all you need to create transformation subclass to create circle shape following below.

     * Enables hardware accelerated rounded corners.
     * original idea here :
    public class RoundedTransformation implements com.squareup.picasso.Transformation {
        private final int radius;
        private final int margin;  // dp

        // radius is corner radii in dp
        // margin is the board in dp
        public RoundedTransformation(final int radius, final int margin) {
            this.radius = radius;
            this.margin = margin;

        public Bitmap transform(final Bitmap source) {
            final Paint paint = new Paint();
            paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

            Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
            Canvas canvas = new Canvas(output);
            canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);

            if (source != output) {

            return output;

        public String key() {
            return "rounded";

After that, what you need to do just load your image with transformation class above.

       .load("...") // Your image source.
       .transform(new RoundedTransformation(50, 4))
       .fit()  // Fix centerCrop issue:


Publish GreenRobot EventBus from Service to Activity/Fragment

I assume that you already know GreenRobot EventBus, and here is how to publish data from android service to your Activity/Fragment.

new Handler(Looper.getMainLooper()).post(new Runnable() {
    public void run() {
        MyData data = new MyData();


Hide Samsung Tablet Soft Keyboard Programatically

Android keyboard usually will show up when there are focus in input widget like EditText. In mobile device we can avoid soft keyboard show up when at first fragment/activity start by defining this code on the input widget xml.


But this method will not work in samsung tablet, in my case Samsung Galaxy Tab.
So we have to hide it programatically to hide samsung soft keyboard. We just need to add this single line on your fragment/activity initialization.



Adding SSL Certificate to Retrofit 2

I assume that you already know how to get SSL certificate from your server and you already put it in android resource inside “raw” directory.


SSL Certificate File

Here is how to read in in android and add to your retrofit.

private static SSLContext getSSLConfig(Context context) throws CertificateException, IOException,
            KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    // Loading CAs from an InputStream
    CertificateFactory cf = null;
    cf = CertificateFactory.getInstance("X.509");

    Certificate ca;
    // I'm using Java7. If you used Java6 close it manually with finally.
    try (InputStream cert = context.getResources().openRawResource(R.raw.your_certificate)) {
        ca = cf.generateCertificate(cert);

    // Creating a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore   = KeyStore.getInstance(keyStoreType);
    keyStore.load(null, null);
    keyStore.setCertificateEntry("ca", ca);

    // Creating a TrustManager that trusts the CAs in our KeyStore.
    String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);

    // Creating an SSLSocketFactory that uses our TrustManager
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, tmf.getTrustManagers(), null);

    return sslContext;

By default Retrofit using OkHttp as the http client library, and here is the last step.

Retrofit.Builder builder = new Retrofit.Builder().baseUrl(Constant.BASE_API_URL);

OkHttpClient okHttp = new OkHttpClient();

Retrofit retrofit = builder.client(okHttp).build();