PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to check internet connection in android without ping or using deprecated code?

 April 20, 2022     android, connection, connectivity, kotlin     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing