check if a Camera app is available before trying to launch it

This commit is contained in:
tibbi 2017-02-07 00:08:32 +01:00
parent 0f0b3cfc30
commit 9a7361795f
12 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,8 @@ import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.activities.SettingsActivity
import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.Config
import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.IMAGES
@ -13,6 +15,7 @@ import com.simplemobiletools.gallery.helpers.VIDEOS
import java.io.File import java.io.File
import java.util.* import java.util.*
fun Context.getRealPathFromURI(uri: Uri): String? { fun Context.getRealPathFromURI(uri: Uri): String? {
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
@ -35,7 +38,12 @@ fun Context.getHumanizedFilename(path: String): String {
} }
fun Context.launchCamera() { fun Context.launchCamera() {
startActivity(Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)) val intent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
toast(R.string.no_camera_app_found)
}
} }
fun Context.launchSettings() { fun Context.launchSettings() {

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Größe ändern</string> <string name="resize">Größe ändern</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Redimensionner</string> <string name="resize">Redimensionner</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Mostrar no mapa</string> <string name="show_on_map">Mostrar no mapa</string>
<string name="unknown_location">Localização desconhecida</string> <string name="unknown_location">Localização desconhecida</string>
<string name="no_map_application">Não existe uma aplicação adequada</string> <string name="no_map_application">Não existe uma aplicação adequada</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Redimensionar</string> <string name="resize">Redimensionar</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Показать место съёмки</string> <string name="show_on_map">Показать место съёмки</string>
<string name="unknown_location">Место съёмки не указано</string> <string name="unknown_location">Место съёмки не указано</string>
<string name="no_map_application">Не найдено приложений с картами</string> <string name="no_map_application">Не найдено приложений с картами</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Изменить размер</string> <string name="resize">Изменить размер</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Ändra storlek</string> <string name="resize">Ändra storlek</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">缩放</string> <string name="resize">缩放</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">縮放</string> <string name="resize">縮放</string>

View File

@ -22,6 +22,7 @@
<string name="show_on_map">Show on map</string> <string name="show_on_map">Show on map</string>
<string name="unknown_location">Unknown location</string> <string name="unknown_location">Unknown location</string>
<string name="no_map_application">No application with maps has been found</string> <string name="no_map_application">No application with maps has been found</string>
<string name="no_camera_app_found">No Camera app has been found</string>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>