From: zerginator Date: Wed, 1 May 2013 18:06:13 +0000 (+0200) Subject: Issue #136 [Feature] Instant upload of videos X-Git-Tag: oc-android-1.7.0_signed~332^2~11 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/536cc166b60733aa54466850ee167163fd2f3cbd Issue #136 [Feature] Instant upload of videos --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 421880f6..d88f6562 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -156,10 +156,14 @@ - + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index ccbea5f1..83ea1548 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -40,7 +40,7 @@ App PIN Protect your client Enable instant uploads - Instantly upload photos taken by camera + Instantly upload media taken by camera Enable Logging This is used to log problems Logging History diff --git a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index 74d20f0d..2c2fa91a 100644 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@ -29,7 +29,7 @@ import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo.State; import android.preference.PreferenceManager; -import android.provider.MediaStore.Images.Media; +import android.provider.MediaStore.*; import android.webkit.MimeTypeMap; import com.owncloud.android.AccountUtils; @@ -41,17 +41,17 @@ import com.owncloud.android.utils.FileStorageUtils; public class InstantUploadBroadcastReceiver extends BroadcastReceiver { - private static String TAG = "PhotoTakenBroadcastReceiver"; - private static final String[] CONTENT_PROJECTION = { Media.DATA, Media.DISPLAY_NAME, Media.MIME_TYPE, Media.SIZE }; - private static String NEW_PHOTO_ACTION = "com.android.camera.NEW_PICTURE"; + private static String TAG = "InstantUploadBroadcastReceiver"; + private static String NEW_PHOTO_ACTION = "android.hardware.action.NEW_PICTURE"; + private static String NEW_VIDEO_ACTION = "android.hardware.action.NEW_VIDEO"; @Override public void onReceive(Context context, Intent intent) { Log_OC.d(TAG, "Received: " + intent.getAction()); if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) { handleConnectivityAction(context, intent); - } else if (intent.getAction().equals(NEW_PHOTO_ACTION)) { - handleNewPhotoAction(context, intent); + } else if (intent.getAction().equals(NEW_PHOTO_ACTION) || intent.getAction().equals(NEW_VIDEO_ACTION)) { + handleNewMediaAction(context, intent); } else if (intent.getAction().equals(FileUploader.UPLOAD_FINISH_MESSAGE)) { handleUploadFinished(context, intent); } else { @@ -71,7 +71,12 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { } } - private void handleNewPhotoAction(Context context, Intent intent) { + private void handleNewMediaAction(Context context, Intent intent) { + Cursor c = null; + String file_path = null; + String file_name = null; + String mime_type = null; + if (!instantUploadEnabled(context)) { Log_OC.d(TAG, "Instant upload disabled, abording uploading"); return; @@ -83,19 +88,36 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { return; } - Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); - - if (!c.moveToFirst()) { - Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); - return; + if (intent.getAction().equals(NEW_PHOTO_ACTION)) { + String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE }; + c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); + if (!c.moveToFirst()) { + Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); + return; + } + file_path = c.getString(c.getColumnIndex(Images.Media.DATA)); + file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); + mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); + Log_OC.w(TAG, "New photo received"); + } + else if (intent.getAction().equals(NEW_VIDEO_ACTION)) { + if (!isConnectedViaWiFi(context)) { + Log_OC.e(TAG, "No Wifi available .. Video instant upload only possible if WiFi is on"); + return; + } + String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE, Video.Media.SIZE }; + c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); + if (!c.moveToFirst()) { + Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); + return; + } + file_path = c.getString(c.getColumnIndex(Video.Media.DATA)); + file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME)); + mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE)); + Log_OC.w(TAG, "New video received"); } - - String file_path = c.getString(c.getColumnIndex(Media.DATA)); - String file_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME)); - String mime_type = c.getString(c.getColumnIndex(Media.MIME_TYPE)); - c.close(); - Log_OC.e(TAG, file_path + ""); + Log_OC.d(TAG, file_path + ""); // same always temporally the picture to upload DbHandler db = new DbHandler(context);