merge in OI distribution
[android_pandora.git] / apps / oi-filemanager / FileManager / src / org / openintents / util / IntentUtils.java
diff --git a/apps/oi-filemanager/FileManager/src/org/openintents/util/IntentUtils.java b/apps/oi-filemanager/FileManager/src/org/openintents/util/IntentUtils.java
new file mode 100644 (file)
index 0000000..e4f71b9
--- /dev/null
@@ -0,0 +1,43 @@
+\r
+\r
+/**\r
+ * Original method retrieved from:\r
+ * http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html\r
+ */\r
+package org.openintents.util;\r
+\r
+import java.util.List;\r
+\r
+import android.content.Context;\r
+import android.content.Intent;\r
+import android.content.pm.PackageManager;\r
+import android.content.pm.ResolveInfo;\r
+\r
+/**\r
+ * \r
+ * @author romainguy\r
+ * @author Peli\r
+ *\r
+ */\r
+public class IntentUtils {\r
+       \r
+       /**\r
+        * Indicates whether the specified action can be used as an intent. This\r
+        * method queries the package manager for installed packages that can\r
+        * respond to the specified intent. If no suitable package is\r
+        * found, this method returns false.\r
+        *\r
+        * @param context The application's environment.\r
+        * @param intent The Intent to check for availability.\r
+        *\r
+        * @return True if an Intent with the specified action can be sent and\r
+        *         responded to, false otherwise.\r
+        */\r
+       public static boolean isIntentAvailable(final Context context, final Intent intent) {\r
+           final PackageManager packageManager = context.getPackageManager();\r
+           List<ResolveInfo> list =\r
+                   packageManager.queryIntentActivities(intent,\r
+                           PackageManager.MATCH_DEFAULT_ONLY);\r
+           return list.size() > 0;\r
+       }\r
+}\r