Set of "whether" judgment methods in Android Development

Source: Internet
Author: User
/*** @ Title hassd * @ description determines whether an SD card exists * @ Param @ return * @ return Boolean * @ date 2012-10-25 9:03:56 */private Boolean hassd () {If (environment. getexternalstoragestate (). equals (Android. OS. environment. media_mounted) return true; else return false ;} /*** @ title isconnect * @ description determines whether a network connection exists * @ Param context * @ return Boolean * @ date 2012-10-22 10:17:18 am * @ author Lizhen */Public stat IC Boolean isconnect (context) {// obtain all connection management objects of the mobile phone (including management of Wi-Fi, net, and other connections) Try {connectivitymanager connectivity = (connectivitymanager) context. getsystemservice (context. connectivity_service); If (connectivity! = NULL) {// obtain the network connection management object networkinfo info = connectivity. getactivenetworkinfo (); If (info! = NULL & info. isconnected () {// determine whether the current network is connected to If (info. getstate () = networkinfo. state. connected) {return true ;}}} catch (exception e) {log. V ("error", E. tostring ();} return false;}/*** @ title isservicerunning * @ Description: determines whether a service is running. The Android system provides the activitymanager function. getrunningservices can list the currently running backend service threads * @ Param servicename * @ Param @ return * @ return Boolean * @ date 9:14:01 * @ author Lizhen */private Boolean isservicerunning (string servicename) {activitymanager manager = (activitymanager) getsystemservice (activity_service); For (runningserviceinfo service: Manager. getrunningservices (integer. max_value) {If (servicename. equals (service. service. getclassname () return true;} return false ;}

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: info-contact@alibabacloud.com 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.