1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.files
;
21 import eu
.alefzero
.owncloud
.AccountUtils
;
22 import eu
.alefzero
.owncloud
.R
;
23 import eu
.alefzero
.owncloud
.files
.services
.InstantUploadService
;
24 import android
.accounts
.Account
;
25 import android
.content
.BroadcastReceiver
;
26 import android
.content
.Context
;
27 import android
.content
.Intent
;
28 import android
.database
.Cursor
;
29 import android
.preference
.Preference
;
30 import android
.preference
.PreferenceManager
;
31 import android
.provider
.MediaStore
.Images
.Media
;
32 import android
.util
.Log
;
34 public class PhotoTakenBroadcastReceiver
extends BroadcastReceiver
{
36 private static String TAG
= "PhotoTakenBroadcastReceiver";
37 private static final String
[] CONTENT_PROJECTION
= { Media
.DATA
, Media
.DISPLAY_NAME
, Media
.MIME_TYPE
, Media
.SIZE
};
39 private static String NEW_PHOTO_ACTION
= "com.android.camera.NEW_PICTURE";
42 public void onReceive(Context context
, Intent intent
) {
43 if (!PreferenceManager
.getDefaultSharedPreferences(context
).getBoolean("instant_uploading", false
)) {
44 Log
.d(TAG
, "Instant upload disabled, abording uploading");
47 if (!intent
.getAction().equals(NEW_PHOTO_ACTION
)) {
48 Log
.e(TAG
, "Incorrect intent sent: " + intent
.getAction());
51 Account account
= AccountUtils
.getCurrentOwnCloudAccount(context
);
52 if (account
== null
) {
53 Log
.w(TAG
, "No owncloud account found for instant upload, abording");
57 Cursor c
= context
.getContentResolver().query(intent
.getData(), CONTENT_PROJECTION
, null
, null
, null
);
59 if (!c
.moveToFirst()) {
60 Log
.e(TAG
, "Couldn't resolve given uri!");
64 String file_path
= c
.getString(c
.getColumnIndex(Media
.DATA
));
65 String file_name
= c
.getString(c
.getColumnIndex(Media
.DISPLAY_NAME
));
66 String mime_type
= c
.getString(c
.getColumnIndex(Media
.MIME_TYPE
));
67 long file_size
= c
.getLong(c
.getColumnIndex(Media
.SIZE
));
71 Intent upload_intent
= new Intent(context
, InstantUploadService
.class);
72 upload_intent
.putExtra(InstantUploadService
.KEY_ACCOUNT
, account
);
73 upload_intent
.putExtra(InstantUploadService
.KEY_FILE_PATH
, file_path
);
74 upload_intent
.putExtra(InstantUploadService
.KEY_DISPLAY_NAME
, file_name
);
75 upload_intent
.putExtra(InstantUploadService
.KEY_FILE_SIZE
, file_size
);
76 upload_intent
.putExtra(InstantUploadService
.KEY_MIME_TYPE
, mime_type
);
78 context
.startService(upload_intent
);