Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Better way to check internet connection? - Gideros Forum

Better way to check internet connection?

rrraptorrrraptor Member
edited October 2016 in General questions
I was wondering how can i implement native share button to my game, and i found this thread. This method still works.
Now i need to check if player have internet connection or not, i created same as for share class in android studio:
package com.giderosmobile.android;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class Connection {
    public static boolean isNetworkAvailable(Activity activity) {
        Context context = activity.getApplicationContext();
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
And simple class (well, i don't realy need a class, just for test):
local bridge = native.getClass("com.giderosmobile.android.plugins.bridge.GBridge")
local activity = bridge.getActivity()
Connection = Core.class()
function Connection:init()
	self.n_class = native.getClass("com.giderosmobile.android.Connection")
function Connection:isNetworkAvailable()
	return self.n_class.isNetworkAvailable(activity)
It works fine, but maybe there is a better way to check network connection? Because it works only for android.


Sign In or Register to comment.