Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <uses-permission android:name="android.permission.INTERNET" />
  2.  
  3. Runtime runtime = Runtime.getRuntime();
  4. try {
  5. Process mIpAddrProcess = runtime.exec("/system/bin/ping -w 2 8.8.8.8");
  6. mExitValue = mIpAddrProcess.waitFor();
  7. BufferedReader reader = new BufferedReader(new InputStreamReader(mIpAddrProcess.getInputStream()));
  8. int i;
  9. char[] buffer = new char[4096];
  10. StringBuffer output = new StringBuffer();
  11. while ((i = reader.read(buffer)) > 0)
  12. output.append(buffer, 0, i);
  13. reader.close();
  14. String str = output.toString();
  15. if (mExitValue == 0)
  16. {
  17. Toast.makeText(getApplicationContext(),"Connection ok"+ str, Toast.LENGTH_SHORT).show();
  18.  
  19. } else
  20. {
  21.  
  22. Toast.makeText(getApplicationContext(), "Please Check Your Internet Connection"+str, Toast.LENGTH_SHORT).show();
  23. //new Description().execute();
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement