Issue
I see many answer for this question but most of the answers using deprecated code & many using ping method to check active internet connection on android that results of getting wrong result on some devices like Samsung. I need a code that could be small & efficient.
Solution
Try this one out its simple and efficient
NetworkInfo info = (NetworkInfo) ((ConnectivityManager)youractivity.this.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null)
{
Toast.makeText(login.this,"No Internet Connection",Toast.LENGTH_SHORT).show();
}
Answered By - MoonLight Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.