Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set to request access network state. Added net detect button. Add net…

… detect logic. Fixed bug which checks array bounds for leave() detection.
  • Loading branch information...
commit c55793c06d4dfb78559d8d2b426514c5fac83941 1 parent bffbc8a
geremy cohen authored
View
1  android/PubnubAndroidTest/3.3/AndroidManifest.xml
@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PubnubTestActivity"
View
9 android/PubnubAndroidTest/3.3/res/layout/main.xml
@@ -64,7 +64,12 @@
android:layout_span="2"
android:stretchColumns="*" >
<TableRow>
- <Button
+ <Button
+ android:id="@+id/netBtn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Net"/>
+ <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -75,7 +80,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="runUnitTest"
- android:text="Run Unit-Test" />
+ android:text="Unit-Test" />
</TableRow>
<TableRow>
<Button
View
2  android/PubnubAndroidTest/3.3/src/com/fbt/Pubnub.java
@@ -770,7 +770,7 @@ private JSONArray _request(List<String> url_components, String channel) {
if (_callFor.equalsIgnoreCase("v2")) {
_callFor = url_components.get(1);
- if(url_components.size()>=6 && url_components.get(6).equals("leave"))
+ if(url_components.size()>=7 && url_components.get(6).equals("leave"))
{
_callFor="leave";
}
View
52 android/PubnubAndroidTest/3.3/src/com/fbt/PubnubTestActivity.java
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.HashMap;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -20,6 +22,7 @@
import android.widget.EditText;
import android.widget.Toast;
+import android.content.Context;
/**
* PubnubTestActivity
*
@@ -245,6 +248,31 @@ public void onClick(DialogInterface dialog,
b.show();
}
});
+
+ Button netBtn = (Button) findViewById(R.id.netBtn);
+ netBtn.setOnClickListener(new OnClickListener() {
+
+ public void onClick(View v) {
+
+ // Android: (net)
+
+ Boolean net = isInternetOn();
+ System.out.println(" net: " + net);
+ final AlertDialog.Builder b = new AlertDialog.Builder(
+ PubnubTestActivity.this);
+ b.setIcon(android.R.drawable.ic_dialog_alert);
+ b.setTitle("net: ");
+ b.setMessage(net.toString());
+ b.setNegativeButton("OK",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int which) {
+ }
+ });
+ b.show();
+ }
+ });
+
}
public void allMessageClick(View v) {
@@ -307,13 +335,35 @@ public void UnitTestDetailedHistoryClick(View v)
UnitTestForDetailedHistory unitTest= new UnitTestForDetailedHistory();
unitTest.RunUnitTest();
}
-
+
+
+ public final boolean isInternetOn() {
+ ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ // ARE WE CONNECTED TO THE NET
+ if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
+ connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
+ connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
+ connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) {
+
+ // MESSAGE TO SCREEN FOR TESTING (IF REQ)
+ Log.e("Net State", "connected");
+ return true;
+ } else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) {
+
+ Log.e("Net State", "not connected");
+ return false;
+ }
+ return false;
+ }
+
public void HereNowClick(View v) {
HashMap<String, Object> args = new HashMap<String, Object>(1);
args.put("channel", channel);
myMessage = pubnub.here_now(args).toString();
r.sendEmptyMessage(0);
Log.e("Here Now", pubnub.here_now(args).toString());
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.