Hello!
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")
end
function Connection:isNetworkAvailable()
return self.n_class.isNetworkAvailable(activity)
end |
It works fine, but maybe there is a better way to check network connection? Because it works only for android.
Comments
The Gobb : https://play.google.com/store/apps/details?id=fr.toastapp.thegobb
Likes: jeromegsq
Likes: vitalitymobile
My test code: https://pastebin.com/MjW8AHWV (because of image url, code isn't shown properly on forum)
I'm getting in my console:
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)