Commit 2b8c54b2 authored by Geoffrey Métais's avatar Geoffrey Métais

VLC install check facilities in extensions SDK

parent 6d3fe851
......@@ -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>
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);
}
}
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);
}
}
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;
}
}
}
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment