Skip to content
This repository
Browse code

Generate error message if library caller does not have Internet permi…

…ssion
  • Loading branch information...
commit e6bd5bc2ea5c693235e62eabd2a61837a461dde4 1 parent 1a44ca8
authored June 07, 2010
6  examples/simple/src/com/facebook/android/Example.java
@@ -25,7 +25,6 @@
25 25
 import com.facebook.android.SessionEvents.LogoutListener;
26 26
 
27 27
 import android.app.Activity;
28  
-import android.app.AlertDialog.Builder;
29 28
 import android.os.Bundle;
30 29
 import android.util.Log;
31 30
 import android.view.View;
@@ -56,11 +55,8 @@ public void onCreate(Bundle savedInstanceState) {
56 55
         super.onCreate(savedInstanceState);
57 56
         
58 57
         if (APP_ID == null) {
59  
-            Builder alertBuilder = new Builder(this);
60  
-            alertBuilder.setTitle("Warning");
61  
-            alertBuilder.setMessage("A Facebook Applicaton ID must be " +
  58
+            Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " +
62 59
                     "specified before running this example: see Example.java");
63  
-            alertBuilder.create().show();
64 60
         }
65 61
         
66 62
         setContentView(R.layout.main);
10  facebook/src/com/facebook/android/Facebook.java
@@ -20,7 +20,9 @@
20 20
 import java.io.IOException;
21 21
 import java.net.MalformedURLException;
22 22
 
  23
+import android.Manifest;
23 24
 import android.content.Context;
  25
+import android.content.pm.PackageManager;
24 26
 import android.os.Bundle;
25 27
 import android.text.TextUtils;
26 28
 import android.util.Log;
@@ -352,7 +354,13 @@ public void dialog(Context context,
352 354
             parameters.putString(TOKEN, getAccessToken());
353 355
         }
354 356
         String url = endpoint + "?" + Util.encodeUrl(parameters);
355  
-        new FbDialog(context, url, listener).show();
  357
+        if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
  358
+                != PackageManager.PERMISSION_GRANTED) {
  359
+            Util.showAlert(context, "Error", 
  360
+                    "Application requires permission to access the Internet");
  361
+        } else {
  362
+            new FbDialog(context, url, listener).show();
  363
+        }
356 364
     }
357 365
 
358 366
     /**
19  facebook/src/com/facebook/android/Util.java
@@ -28,6 +28,7 @@
28 28
 import org.json.JSONException;
29 29
 import org.json.JSONObject;
30 30
 
  31
+import android.app.AlertDialog.Builder;
31 32
 import android.content.Context;
32 33
 import android.os.Bundle;
33 34
 import android.util.Log;
@@ -202,4 +203,22 @@ public static JSONObject parseJson(String response)
202 203
         }
203 204
         return json;
204 205
     }
  206
+    
  207
+    /**
  208
+     * Display a simple alert dialog with the given text and title.
  209
+     * 
  210
+     * @param context 
  211
+     *          Android context in which the dialog should be displayed
  212
+     * @param title 
  213
+     *          Alert dialog title
  214
+     * @param text
  215
+     *          Alert dialog message
  216
+     */
  217
+    public static void showAlert(Context context, String title, String text) {
  218
+        Builder alertBuilder = new Builder(context);
  219
+        alertBuilder.setTitle(title);
  220
+        alertBuilder.setMessage(text);
  221
+        alertBuilder.create().show();
  222
+    }
  223
+
205 224
 }

0 notes on commit e6bd5bc

Please sign in to comment.
Something went wrong with that request. Please try again.