resolve take photo uri for internal use

This commit is contained in:
Daniel Gultsch 2016-10-03 18:26:11 +02:00
parent f4a883848c
commit cea52b0722
2 changed files with 5 additions and 5 deletions

View file

@ -14,7 +14,6 @@ import android.media.MediaMetadataRetriever;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.FileObserver;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
@ -58,7 +57,7 @@ import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.pep.Avatar;
public class FileBackend { public class FileBackend {
private final SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US); private static final SimpleDateFormat IMAGE_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
private XmppConnectionService mXmppConnectionService; private XmppConnectionService mXmppConnectionService;
@ -437,7 +436,7 @@ public class FileBackend {
} }
public Uri getTakePhotoUri() { public Uri getTakePhotoUri() {
File file = new File(getTakePhotoPath()+"IMG_" + this.imageDateFormat.format(new Date()) + ".jpg"); File file = new File(getTakePhotoPath()+"IMG_" + this.IMAGE_DATE_FORMAT.format(new Date()) + ".jpg");
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return FileProvider.getUriForFile(mXmppConnectionService, "eu.siacs.conversations.files", file); return FileProvider.getUriForFile(mXmppConnectionService, "eu.siacs.conversations.files", file);

View file

@ -1404,14 +1404,15 @@ public class ConversationActivity extends XmppActivity
} }
} else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) { } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
if (mPendingImageUris.size() == 1) { if (mPendingImageUris.size() == 1) {
Uri uri = mPendingImageUris.get(0); Uri uri = FileBackend.getIndexableTakePhotoUri(mPendingImageUris.get(0));
mPendingImageUris.set(0, uri);
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
Log.d(Config.LOGTAG,"ConversationsActivity.onActivityResult() - attaching image to conversations. TAKE_PHOTO"); Log.d(Config.LOGTAG,"ConversationsActivity.onActivityResult() - attaching image to conversations. TAKE_PHOTO");
attachImageToConversation(getSelectedConversation(), uri); attachImageToConversation(getSelectedConversation(), uri);
mPendingImageUris.clear(); mPendingImageUris.clear();
} }
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(FileBackend.getIndexableTakePhotoUri(uri)); intent.setData(uri);
sendBroadcast(intent); sendBroadcast(intent);
} else { } else {
mPendingImageUris.clear(); mPendingImageUris.clear();