diff --git a/src/android/org/linphone/ChatFragment.java b/src/android/org/linphone/ChatFragment.java index 342288ef3..67534f69a 100644 --- a/src/android/org/linphone/ChatFragment.java +++ b/src/android/org/linphone/ChatFragment.java @@ -756,7 +756,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC if(path.contains("file://")) { path = path.substring(7); } - + if(path.contains("%20")) { + path = path.replace("%20", "-"); + } LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); if(newChatConversation && chatRoom == null) { @@ -765,7 +767,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC initChatRoom(address); } } - if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) { try { Bitmap bm = BitmapFactory.decodeFile(path); @@ -785,12 +786,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } private void sendFileSharingMessage(String path, int size ) { - if(path.contains("file://")) { + if (path.contains("file://")) { path = path.substring(7); - }else if(path.contains("com.android.contacts/contacts/")){ + } else if (path.contains("com.android.contacts/contacts/")) { path = getCVSPathFromLookupUri(path).toString(); - } else if(path.contains("vcard") || path.contains("vcf")) { + } else if (path.contains("vcard") || path.contains("vcf")) { path = (LinphoneUtils.createCvsFromString(LinphoneActivity.instance().getCVSPathFromOtherUri(path).toString())).toString(); + } else if (path.contains("content://")){ + path = LinphoneUtils.getFilePath(this.getActivity().getApplicationContext(), Uri.parse(path)); + } + if(path.contains("%20")) { + path = path.replace("%20", "-"); } LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); @@ -913,15 +919,20 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC private void pickImage() { List cameraIntents = new ArrayList(); Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()))); + File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg")); imageToUploadUri = Uri.fromFile(file); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri); cameraIntents.add(captureIntent); Intent galleryIntent = new Intent(); - galleryIntent.setType("*/*"); + galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_PICK); + Intent fileIntent = new Intent(); + fileIntent.setType("*/*"); + fileIntent.setAction(Intent.ACTION_GET_CONTENT); + cameraIntents.add(fileIntent); + Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{})); @@ -1124,7 +1135,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { - if(data != null) { + if(data != null) { if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) { String fileToUploadPath = null; if (data != null && data.getData() != null) { @@ -1138,8 +1149,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } else { fileToUploadPath = getRealPathFromURI(data.getData()); } - if (fileToUploadPath == null) + if (fileToUploadPath == null) { fileToUploadPath = data.getData().toString(); + } } else if (imageToUploadUri != null) { fileToUploadPath = imageToUploadUri.getPath(); } @@ -1518,7 +1530,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC loadBitmap(appData, holder.messageImage); holder.messageImage.setTag(message.getAppData()); } - } } } @@ -1628,6 +1639,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC file = new File(imageUri); contentUri = FileProvider.getUriForFile(getActivity(), "org.linphone.provider", file); } else if (imageUri.startsWith("content://")) { + Log.e("===>>> ChatFragment - getView() - imageUri = "+imageUri); contentUri = Uri.parse(imageUri); } else { file = new File(imageUri); diff --git a/src/android/org/linphone/LinphoneUtils.java b/src/android/org/linphone/LinphoneUtils.java index c66d0af71..c265a146a 100644 --- a/src/android/org/linphone/LinphoneUtils.java +++ b/src/android/org/linphone/LinphoneUtils.java @@ -43,6 +43,7 @@ import android.util.TypedValue; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; +import android.webkit.MimeTypeMap; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; @@ -738,16 +739,15 @@ public final class LinphoneUtils { ************************************************************************************************/ public static String getFilePath(final Context context, final Uri uri) { - // Google photo uri example // content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2FAF1QipMObgoK_wDY66gu0QkMAi/ORIGINAL/NONE/114919 - if ("content".equalsIgnoreCase(uri.getScheme())) { + String type = getTypeFromUri(uri, context); String result = getDataColumn(context, uri, null, null); // if (TextUtils.isEmpty(result)) - if (uri.getAuthority().contains("com.google.android")) { + if (uri.getAuthority().contains("com.google.android") || uri.getAuthority().contains("com.android")) { try { - File localFile = createImageFile(context, null); + File localFile = createFile(context, null, type); FileInputStream remoteFile = getSourceStream(context, uri); if(copyToFile(remoteFile, localFile)) result = localFile.getAbsolutePath(); @@ -762,10 +762,17 @@ public final class LinphoneUtils { else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } - return null; } + + private static String getTypeFromUri(Uri uri, Context context){ + ContentResolver cR = context.getContentResolver(); + MimeTypeMap mime = MimeTypeMap.getSingleton(); + String type = mime.getExtensionFromMimeType(cR.getType(uri)); + return type; + } + /** * Copy data from a source stream to destFile. * Return true if succeed, return false if failed. @@ -797,9 +804,9 @@ public final class LinphoneUtils { } } - public static File createImageFile(Context context, String imageFileName) throws IOException { + public static File createFile(Context context, String imageFileName, String type) throws IOException { if (TextUtils.isEmpty(imageFileName)) - imageFileName = getTimestamp()+".JPEG"; // make random filename if you want. + imageFileName = getTimestamp()+"."+type; // make random filename if you want. final File root; imageFileName = imageFileName;