Android determines whether there is a network N Method

Source: Internet
Author: User

1 ./**

* Obtain the network connection method.
*
* @ Param context
* @ Return
*/
Public static NetworkInfo getActiveNetwork (Context context)
{
If (context = null)
Return null;
ConnectivityManager mConnMgr = (ConnectivityManager) context
. GetSystemService (Context. CONNECTIVITY_SERVICE );
If (mConnMgr = null)
Return null;
NetworkInfo aActiveInfo = mConnMgr. getActiveNetworkInfo ();
// Obtain the active network connection information
Return aActiveInfo;
}

PS: network if (null! = NetworkInfo getActiveNetwork (Context context ))


2 ./**

* Determine whether the SD card can be read and written
*
* @ Return
*/
Public static boolean isCanUseSdCard ()
{
Try
{
Return Environment. getExternalStorageState (). equals (
Environment. MEDIA_MOUNTED );
}
Catch (Exception e)
{
E. printStackTrace ();
}
Return false;
}


3 ./**

* Checks whether all strings are Chinese characters.
*
* @ Param name
* @ Return
*/
Public static boolean checkNameChese (String name)
{
Boolean res = true;
Char [] cTemp = name. toCharArray ();
For (int I = 0; I <name. length (); I ++)
{
If (! IsChinese (cTemp [I])
{
Res = false;
Break;
}
}
Return res;
}

4 ./**

* Read local or network images and convert them to Bitmap
*
* @ Param url
* @ Return
*/
Public static Bitmap returnBitmap (String url)
{
URL myFileUrl = null;
Bitmap bitmap = null;
Try
{
MyFileUrl = new URL (url );
}
Catch (MalformedURLException e)
{
E. printStackTrace ();
}
Try
{
HttpURLConnection conn = (HttpURLConnection) myFileUrl
. OpenConnection ();
Conn. setDoInput (true );
Conn. connect ();
InputStream is = conn. getInputStream ();
Bitmap = BitmapFactory. decodeStream (is );
Is. close ();
}
Catch (IOException e)
{
E. printStackTrace ();
}
Return bitmap;
}

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: 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.