I am building an application which triggers an alarm via AlarmManager.
I would like to be able to call the Alarm via it\'s own non-activity class, but since I am not
Use this in Activity:
private Context context = this;
........
if(Utils.isInternetAvailable(context){
Utils.showToast(context, "toast");
}
..........
in Utils:
public class Utils {
public static boolean isInternetAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
public static void showToast(Context context, String text) {
Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}