Permalink
Browse files

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

…ssion
  • Loading branch information...
Steven Soneff
Steven Soneff committed Jun 8, 2010
1 parent 1a44ca8 commit e6bd5bc2ea5c693235e62eabd2a61837a461dde4
@@ -25,7 +25,6 @@
import com.facebook.android.SessionEvents.LogoutListener;
import android.app.Activity;
-import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@@ -56,11 +55,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (APP_ID == null) {
- Builder alertBuilder = new Builder(this);
- alertBuilder.setTitle("Warning");
- alertBuilder.setMessage("A Facebook Applicaton ID must be " +
+ Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " +
"specified before running this example: see Example.java");
- alertBuilder.create().show();
}
setContentView(R.layout.main);
@@ -20,7 +20,9 @@
import java.io.IOException;
import java.net.MalformedURLException;
+import android.Manifest;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -352,7 +354,13 @@ public void dialog(Context context,
parameters.putString(TOKEN, getAccessToken());
}
String url = endpoint + "?" + Util.encodeUrl(parameters);
- new FbDialog(context, url, listener).show();
+ if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
+ != PackageManager.PERMISSION_GRANTED) {
+ Util.showAlert(context, "Error",
+ "Application requires permission to access the Internet");
+ } else {
+ new FbDialog(context, url, listener).show();
+ }
}
/**
@@ -28,6 +28,7 @@
import org.json.JSONException;
import org.json.JSONObject;
+import android.app.AlertDialog.Builder;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
@@ -202,4 +203,22 @@ public static JSONObject parseJson(String response)
}
return json;
}
+
+ /**
+ * Display a simple alert dialog with the given text and title.
+ *
+ * @param context
+ * Android context in which the dialog should be displayed
+ * @param title
+ * Alert dialog title
+ * @param text
+ * Alert dialog message
+ */
+ public static void showAlert(Context context, String title, String text) {
+ Builder alertBuilder = new Builder(context);
+ alertBuilder.setTitle(title);
+ alertBuilder.setMessage(text);
+ alertBuilder.create().show();
+ }
+
}

0 comments on commit e6bd5bc

Please sign in to comment.