[Android] VLC install check facilities in extensions SDK
Geoffrey Métais
git at videolan.org
Tue Feb 2 17:51:36 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 2 17:47:08 2016 +0100| [2b8c54b2189507eae18b4dc19e1f472218e4b497] | committer: Geoffrey Métais
VLC install check facilities in extensions SDK
> https://code.videolan.org/videolan/vlc-android/commit/2b8c54b2189507eae18b4dc19e1f472218e4b497
---
api/src/main/AndroidManifest.xml | 2 ++
.../vlc/extensions/api/WarningActivity.java | 15 ++++++++++++
.../videolan/vlc/extensions/api/tools/Dialogs.java | 20 ++++++++++++++++
.../videolan/vlc/extensions/api/tools/Helpers.java | 27 ++++++++++++++++++++++
api/src/main/res/values/strings.xml | 2 ++
5 files changed, 66 insertions(+)
diff --git a/api/src/main/AndroidManifest.xml b/api/src/main/AndroidManifest.xml
index 887ccdf..08aa4b1 100644
--- a/api/src/main/AndroidManifest.xml
+++ b/api/src/main/AndroidManifest.xml
@@ -27,6 +27,8 @@
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
+ <activity android:name="org.videolan.vlc.extensions.api.WarningActivity"
+ android:theme="@style/TransparentTheme" />
</application>
</manifest>
diff --git a/api/src/main/java/org/videolan/vlc/extensions/api/WarningActivity.java b/api/src/main/java/org/videolan/vlc/extensions/api/WarningActivity.java
new file mode 100644
index 0000000..832e2d4
--- /dev/null
+++ b/api/src/main/java/org/videolan/vlc/extensions/api/WarningActivity.java
@@ -0,0 +1,15 @@
+package org.videolan.vlc.extensions.api;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import org.videolan.vlc.extensions.api.tools.Dialogs;
+
+public class WarningActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Dialogs.showInstallVlc(this);
+ }
+}
diff --git a/api/src/main/java/org/videolan/vlc/extensions/api/tools/Dialogs.java b/api/src/main/java/org/videolan/vlc/extensions/api/tools/Dialogs.java
index a3c14c8..6fd905b 100644
--- a/api/src/main/java/org/videolan/vlc/extensions/api/tools/Dialogs.java
+++ b/api/src/main/java/org/videolan/vlc/extensions/api/tools/Dialogs.java
@@ -1,8 +1,10 @@
package org.videolan.vlc.extensions.api.tools;
+import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -89,4 +91,22 @@ public class Dialogs {
}
}, null);
}
+
+ public static AlertDialog showInstallVlc(@NonNull final Activity activity) {
+ return showAlertDialog(activity, R.string.vlc_error_title, R.string.vlc_error_message,
+ new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ dialog.dismiss();
+ activity.finish();
+ }
+ }, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=org.videolan.vlc")));
+ dialog.dismiss();
+ activity.finish();
+ }
+ }, null);
+ }
}
diff --git a/api/src/main/java/org/videolan/vlc/extensions/api/tools/Helpers.java b/api/src/main/java/org/videolan/vlc/extensions/api/tools/Helpers.java
new file mode 100644
index 0000000..0fabfe8
--- /dev/null
+++ b/api/src/main/java/org/videolan/vlc/extensions/api/tools/Helpers.java
@@ -0,0 +1,27 @@
+package org.videolan.vlc.extensions.api.tools;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+
+import org.videolan.vlc.extensions.api.WarningActivity;
+
+public class Helpers {
+
+ /**
+ * Helper method to check if VLC is installed on device. If not, shows an AlertDialog and offers
+ * the user to install it from the Play Store.
+ * @param context A simple context reference
+ * @return true is VLC is installed, false if not.
+ */
+ public static boolean checkVlc(Context context) {
+ PackageManager pm = context.getPackageManager();
+ try {
+ pm.getPackageInfo("org.videolan.vlc", 0);
+ return true;
+ } catch (PackageManager.NameNotFoundException e) {
+ context.startActivity(new Intent(context, WarningActivity.class));
+ return false;
+ }
+ }
+}
diff --git a/api/src/main/res/values/strings.xml b/api/src/main/res/values/strings.xml
index 86bf7e7..64d68c6 100644
--- a/api/src/main/res/values/strings.xml
+++ b/api/src/main/res/values/strings.xml
@@ -2,4 +2,6 @@
<string name="app_name">VLC extension library</string>
<string name="network_error_title">No Internet connection</string>
<string name="network_error_message">This extension needs your device to be connected to internet</string>
+ <string name="vlc_error_title">VLC is not installed</string>
+ <string name="vlc_error_message">This feature needs VLC application to be installed on your device</string>
</resources>
More information about the Android
mailing list