Back to project page ElyTheme.
The source code is released under:
GNU General Public License
If you think the Android project ElyTheme listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.afollestad.silk; /* w w w . j av a2 s . c o m*/ import android.Manifest; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.net.ConnectivityManager; import android.net.NetworkInfo; import java.util.List; /** * Various convenience methods. * * @author Aidan Follestad (afollestad) */ public class Silk { /** * Checks if the device is currently online, works for both wifi and mobile networks. */ public static boolean isOnline(Context context) { if (context == null) return false; boolean state = false; ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null) state = wifiNetwork.isConnectedOrConnecting(); NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null) state = mobileNetwork.isConnectedOrConnecting(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) state = activeNetwork.isConnectedOrConnecting(); return state; } /** * Checks whether or not the calling app has permission to access the internet. */ public static boolean hasInternetPermission(Context context) { return declaresPermission(context, Manifest.permission.INTERNET); } public static boolean declaresPermission(Context context, String permission) { int res = context.checkCallingOrSelfPermission(permission); return res == PackageManager.PERMISSION_GRANTED; } /** * Checks if there's any apps available to open a certain intent on the current device. */ public static boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } /** * Detects whether or not the device is a tablet. */ public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } }