Skip to content

Commit 9434405

Browse files
committed
Network status check added.
1 parent 95ce5a0 commit 9434405

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

Source/GDApi/gdapi/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:minSdkVersion="16"
99
android:targetSdkVersion="25" />
1010
<uses-permission android:name="android.permission.INTERNET"/>
11+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1112

1213
<application
1314
android:allowBackup="true"

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDad.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public void init(Activity mContext) {
4646

4747
if (devListener != null) devListener.onAPIReady();
4848

49-
if(GDGameData.preRoll){
50-
showBanner("{isInterstitial:" + true + "}");
51-
}
5249
}
5350

5451
public void init(Activity mContext, boolean isCordovaPlugin) {
@@ -58,9 +55,6 @@ public void init(Activity mContext, boolean isCordovaPlugin) {
5855

5956
if (devListener != null) devListener.onAPIReady();
6057

61-
if(GDGameData.preRoll){
62-
showBanner("{isInterstitial:" + true + "}");
63-
}
6458

6559
} else {
6660
init(mContext);
@@ -346,7 +340,7 @@ public void showBanner(String args) {
346340
String bundleId = GDGameData.bundleId;
347341
String msize = "interstitial";
348342
if(!gDshowObj.isInterstitial) msize = gDshowObj.size;
349-
String url = "http://pub.tunnl.com/oppm?bundleid="+bundleId+"&msize="+msize;
343+
String url = "http://pub.tunnl.com/oppm?bundleid=and."+bundleId+"&msize="+msize;
350344

351345
// getting unit id from tunnl for ad request
352346
GDHttpRequest.sendHttpRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
@@ -408,22 +402,22 @@ private void requestHandler(final GDshowObj gDshowObj){
408402
gdRequestAdHandler = new GDRequestAdHandler() {
409403
@Override
410404
public void Succes() {
411-
GDHttpRequest.sendStringRequest(GDlogger.mContext, tunnlData.get(currentRequestInd).getImp(), Request.Method.GET, null, new GDHttpCallback() {
405+
GDHttpRequest.sendStringRequest(GDlogger.mContext, tunnlData.get(currentRequestInd).getImp().replace("https", "http"), Request.Method.GET, null, new GDHttpCallback() {
412406
@Override
413407
public void onSuccess(JSONObject data) {
408+
GDutils.log("Imp");
414409
}
415410

416411
@Override
417412
public void onError(VolleyError error) {
413+
GDutils.log("Imp error");
418414
}
419415
});
420416
}
421417

422418
@Override
423419
public void Error(String err) {
424-
425-
//ToDO add use error listener here for user.
426-
420+
427421
String url = tunnlData.get(currentRequestInd).getErr().replace("https","http");
428422
GDHttpRequest.sendStringRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
429423
@Override

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDbanner.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GDbanner {
1414
protected static void init() {
1515

1616
if(GDstatic.enable && !GDstatic.testAds) {
17-
String url = GDstatic.GAME_API_URL + '/' + GDstatic.gameId;
17+
String url = GDstatic.GAME_API_URL+ '/' + GDstatic.gameId;
1818
GDHttpRequest.sendHttpRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
1919
@Override
2020
public void onSuccess(JSONObject data) {
@@ -106,6 +106,9 @@ protected static void ShowBanner(String args) {
106106

107107
} else {
108108
GDutils.log("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
109+
if (GDlogger.gDad.devListener != null) {
110+
GDlogger.gDad.devListener.onBannerFailed("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
111+
}
109112
}
110113
}
111114
else {
@@ -119,6 +122,9 @@ protected static void ShowBanner(String args) {
119122

120123
} else {
121124
GDutils.log("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
125+
if (GDlogger.gDad.devListener != null) {
126+
GDlogger.gDad.devListener.onBannerFailed("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
127+
}
122128
}
123129
}
124130
} else {

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDlogger.java

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.gd.analytics;
22

33
import android.app.Activity;
4+
import android.content.Context;
5+
import android.net.ConnectivityManager;
6+
import android.net.NetworkInfo;
47
import android.util.Log;
58

69
public class GDlogger {
@@ -20,21 +23,34 @@ public class GDlogger {
2023
public static void init(String gameId, String regId, Activity _mContext) {
2124

2225
mContext = _mContext;
23-
if (GDstatic.enable) {
24-
GDutils.log("API is already Initialized.");
25-
} else {
26-
mContext = _mContext;
2726

28-
String[] gameserver = regId.toLowerCase().split("-");
29-
GDstatic.serverId = gameserver[5];
30-
GDstatic.regId = gameserver[0] + "-" + gameserver[1] + "-" + gameserver[2] + "-" + gameserver[3] + "-" + gameserver[4];
31-
GDstatic.gameId = gameId;
27+
if(GDutils.isOnline(mContext)){
28+
29+
if (GDstatic.enable) {
30+
GDutils.log("API is already Initialized.");
31+
} else {
32+
mContext = _mContext;
33+
34+
String[] gameserver = regId.toLowerCase().split("-");
35+
GDstatic.serverId = gameserver[5];
36+
GDstatic.regId = gameserver[0] + "-" + gameserver[1] + "-" + gameserver[2] + "-" + gameserver[3] + "-" + gameserver[4];
37+
GDstatic.gameId = gameId;
3238

33-
GDstatic.enable = true;
39+
GDstatic.enable = true;
40+
41+
GDbanner.init();
42+
GDutils.log("Game Distribution Android API Init");
43+
}
3444

35-
GDbanner.init();
36-
GDutils.log("Game Distribution Android API Init");
3745
}
46+
else{
47+
48+
if(GDlogger.gDad.devListener != null)
49+
GDlogger.gDad.devListener.onAPINotReady("API cannot connect to internet. Please check the network connection.");
50+
51+
}
52+
53+
3854
}
3955

4056
public static void init(String gameId, String regId, Activity _mContext, boolean isCordovaPlugin) {
@@ -65,23 +81,38 @@ public static void enableTestAds() {
6581
*/
6682
public static void ShowBanner(String size, String alignment, String position) {
6783

68-
String args = "{isInterstitial:false,size:" + size + ",alignment:" + alignment + ",position:" + position + "}";
84+
if(GDutils.isOnline(mContext)){
85+
String args = "{isInterstitial:false,size:" + size + ",alignment:" + alignment + ",position:" + position + "}";
6986

70-
if (GDstatic.enable) {
71-
GDbanner.ShowBanner(args);
72-
} else {
73-
Log.i("GDLogger", "GDApi is not initialized!");
87+
if (GDstatic.enable) {
88+
GDbanner.ShowBanner(args);
89+
} else {
90+
Log.i("GDLogger", "GDApi is not initialized!");
91+
}
92+
}
93+
else{
94+
if(GDlogger.gDad.devListener != null)
95+
GDlogger.gDad.devListener.onBannerFailed("API cannot connect to internet. Please check the network connection.");
7496
}
97+
98+
7599
}
76100

77101
public static void ShowBanner(Boolean isInterstitial) {
78102

79-
String args = "{isInterstitial:" + isInterstitial + "}";
80-
if (GDstatic.enable) {
81-
GDbanner.ShowBanner(args);
82-
} else {
83-
Log.i("GDLogger", "GDApi is not initialized!");
103+
if(GDutils.isOnline(mContext)){
104+
String args = "{isInterstitial:" + isInterstitial + "}";
105+
if (GDstatic.enable) {
106+
GDbanner.ShowBanner(args);
107+
} else {
108+
Log.i("GDLogger", "GDApi is not initialized!");
109+
}
110+
}
111+
else{
112+
if(GDlogger.gDad.devListener != null)
113+
GDlogger.gDad.devListener.onBannerFailed("API cannot connect to internet. Please check the network connection.");
84114
}
115+
85116
}
86117

87118
public static void setAdListener(GDadListener gDadListener) {
@@ -98,4 +129,5 @@ public static void hideBanner() {
98129
}
99130
}
100131

132+
101133
}

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDutils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.gd.analytics;
22

3+
import android.app.Activity;
34
import android.app.ActivityManager;
45
import android.app.ActivityManager.RunningTaskInfo;
56
import android.content.ComponentName;
67
import android.content.Context;
8+
import android.net.ConnectivityManager;
9+
import android.net.NetworkInfo;
710
import android.util.Log;
811

912
import java.util.List;
@@ -37,4 +40,11 @@ protected static boolean isApplicationBroughtToBackground() {
3740
return false;
3841
}
3942

43+
public static boolean isOnline(Activity mContext) {
44+
ConnectivityManager cm =
45+
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
46+
NetworkInfo netInfo = cm.getActiveNetworkInfo();
47+
return netInfo != null && netInfo.isConnectedOrConnecting();
48+
}
49+
4050
}

0 commit comments

Comments
 (0)