Android Tools sorting (1) Check if there is a network, check if the SD card exists

Source: Internet
Author: User

The following tool classes are mainly used for:
(1) Check if there is a network,
(2) Check if there is WiFi,
(3) Check if there is a mobile network

ImportAndroid.content.Context;;; Public  class commonutils {    /** Check if there is a network * /     Public Static Boolean isnetworkavailable(Context context) {Networkinfo info = getnetworkinfo (context);if(Info! =NULL) {returnInfo.isavailable (); }return false; }/** Check if it is WiFi * /     Public Static Boolean Iswifi(Context context) {Networkinfo info = getnetworkinfo (context);if(Info! =NULL) {if(Info.gettype () = = Connectivitymanager.type_wifi)return true; }return false; }/** Check if it is a mobile network * /     Public Static Boolean IsMobile(Context context) {Networkinfo info = getnetworkinfo (context);if(Info! =NULL) {if(Info.gettype () = = Connectivitymanager.type_mobile)return true; }return false; }Private StaticNetworkinfoGetnetworkinfo(Context context) {Connectivitymanager cm = (connectivitymanager) context. Getsystemservice (Context.connectivity_serv ICE);returnCm.getactivenetworkinfo (); }/** Check if the SD card is present * /     Public Static Boolean Checksdcard() {if(Android.os.Environment.getExternalStorageState (). Equals (Android.os.Environment.MEDIA_MOUNTED))return true;Else            return false; }}

Android Tools sorting (1) Check if there is a network, check if the SD card exists

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.