I am developing an android application. It uses some network service like:
- Firebase Firestore
- 3rd party REST API
- Ping.
When I develop this, everything works fine. So I tested it on my phone, and I uploaded it in the play store. After uploaded to the play store, I tried to download and tested. But ping is only failed!!!
I cannot understand this situation.
First, Firebase Firestore works fine.
Second, I am using 3rd party REST API. To using the service, I am using "Retrofit" library. It works fine too.
Third, my app has the feature to check server status. For this feature, I implemented "ping". This is just ping.
"ping -c 1 xxx.xxx.xxx.xxx"
And show the latency to the end user. It works fine in debug/release/signed APK.
But it doesn't work when I download from the play store.
I just added only one permission.
<uses-permission android:name="android.permission.INTERNET" />
Should I define ACCESS_NETWORK_STATE permission too? But Firestore and other 3rd party REST API works fine.
Below is my 'build.gradle' file.
android {
signingConfigs {
config {
keyAlias xxx
keyPassword xxx
storeFile xxx
storePassword 'xxx'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
multiDexEnabled true
applicationId "xxx"
minSdkVersion 22
targetSdkVersion 25
versionCode 16
versionName "1.1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
}
}
productFlavors {
}
}
And my "proguard-rules.pro" file is empty.
Below is my code to get the ping information.
public static String ping(String host) throws IOException, InterruptedException {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ping -c 1 -w 3 " + host);
proc.waitFor();
int exit = proc.exitValue();
if (exit == 0) {
StringBuffer echo = new StringBuffer();
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
String line = "";
while ((line = buffer.readLine()) != null) {
echo.append(line + "\n");
}
}
return getPingStats(echo.toString());
} else if (exit == 1) {
pingError = "failed, exit = 1";
Log.e(TAG, "[CHICKEN] ping - error: " + pingError);
return null;
} else {
pingError = "error, exit = 2";
Log.e(TAG, "[CHICKEN] ping - error: " + pingError);
return null;
}
}