[File sharing] fix file picking in chat
This commit is contained in:
parent
ee32ce38e7
commit
678655ecd8
2 changed files with 36 additions and 17 deletions
|
@ -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);
|
||||
|
@ -791,6 +792,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
path = getCVSPathFromLookupUri(path).toString();
|
||||
} 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<Intent> cameraIntents = new ArrayList<Intent>();
|
||||
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[]{}));
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue