Posted on Leave a comment

Android ImageView not displaying image in few phones only

Issue:

Android ImageView was not displaying image on Redmi Note Prime, when tested. But the same code when used in Redmi 4A shows image. 

Image which was being used

Solutions tried:

  1. Setting Image using XML
    Used: 
    android:src
  2. Setting image using Java code
    Used: 
    ImageView img;
    img = (ImageView) findViewById(R.id.startscreen);
    img.setImageResource(R.drawable.startimage);
  3. Setting background to different colour
    Used:
    android:background
  4. Changing the background colour of image
  5. Using AppCompat
    Used: 
    app:srcCompat

Solution that worked:

After googling all possible methods, we came across a comment where ‘Resizing the image’ was an option.

Initially, our image had a resolution of 1587 x 2245. We reduced the pixels by half (50%). And then tried without changing the code. Changing the image resolution did the trick for us !

In case you are stuck with image being displayed on a device and not on another, either use multi-resolution content, or use content that fits into all.

Posted on Leave a comment

Android Code : Ping a domain/IP & Latency Calculation

The following code may be used to ping the IP / Domain addresses and to obtain latency

Tested in Android 4.4.2, 6.0
Mobile handsets: Lenovo A6000, Redmi Note 4A
Working application: PUBG Network Quality Check
Minimum API Tested: 19

public long pingg (String domain){
        Runtime runtime = Runtime.getRuntime();
        try {
            long a = (System.currentTimeMillis() % 100000);
            Process ipProcess = runtime.exec("/system/bin/ping -c 1 "+domain);
            ipProcess.waitFor();
            long b = (System.currentTimeMillis() % 100000);
            if (b <= a) {
                timeofping = ((100000 - a) + b);
            } else {
                timeofping = (b - a);
            }
        }catch (Exception e){

        }
        return timeofping;
    }

Explanation:
The code fetches the current time in milliseconds to a variable.
The ping function is then called, with the domain as the parameter.
The code waits till the pinging is over.
The current time in milliseconds is fetched again.
The time interval between this is calculated as latency.

Special Thanks to StackOverflow for the idea and code concept !