close #21, allow opening images and videos with third party apps

This commit is contained in:
tibbi 2016-10-08 21:28:16 +02:00
parent 4398443a0d
commit 7cd62075e7
10 changed files with 41 additions and 5 deletions

View File

@ -102,14 +102,17 @@ public class Utils {
final Uri uri = Uri.fromFile(file);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
if (medium.getIsVideo()) {
intent.setType("video/*");
} else {
intent.setType("image/*");
}
intent.setType(getMimeType(medium));
activity.startActivity(Intent.createChooser(intent, shareTitle));
}
public static String getMimeType(Medium medium) {
if (medium.getIsVideo())
return "video/*";
else
return "image/*";
}
public static void showSystemUI(ActionBar actionbar, Window window) {
if (actionbar != null)
actionbar.show();

View File

@ -149,6 +149,9 @@ public class ViewPagerActivity extends SimpleActivity
case R.id.menu_set_as_wallpaper:
setAsWallpaper();
return true;
case R.id.menu_open_with:
openWith();
return true;
case R.id.menu_share:
shareMedium();
return true;
@ -197,6 +200,18 @@ public class ViewPagerActivity extends SimpleActivity
}
}
private void openWith() {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(getCurrentFile()), Utils.getMimeType(getCurrentMedium()));
final Intent chooser = Intent.createChooser(intent, getString(R.string.open_with));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
} else {
Utils.showToast(getApplicationContext(), R.string.no_app_found);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == EDIT_IMAGE) {

View File

@ -5,6 +5,10 @@
android:id="@+id/menu_set_as_wallpaper"
android:title="@string/set_as_wallpaper"
app:showAsAction="never"/>
<item
android:id="@+id/menu_open_with"
android:title="@string/open_with"
app:showAsAction="never"/>
<item
android:id="@+id/menu_edit"
android:icon="@mipmap/edit"

View File

@ -29,6 +29,8 @@
<string name="descending">Absteigend</string>
<string name="ok">OK</string>
<string name="cancel">Abbrechen</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 Ordner gelöscht</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descendente</string>
<string name="ok">Aceptar</string>
<string name="cancel">Cancelar</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 carpeta eliminada</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descending</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 cartella eliminata</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descending</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 フォルダーを削除しました</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descendente</string>
<string name="ok">OK</string>
<string name="cancel">Cancelar</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 pasta eliminada</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descending</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 mapp borttagen</item>

View File

@ -29,6 +29,8 @@
<string name="descending">Descending</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="open_with">Open with</string>
<string name="no_app_found">No valid app found</string>
<plurals name="folders_deleted">
<item quantity="one">1 folder deleted</item>