mirror of
https://github.com/DrKLO/Telegram.git
synced 2025-01-18 15:20:33 +01:00
fix sharing remote images from another application
This commit is contained in:
parent
0907dfaa45
commit
4d79111c96
4 changed files with 42 additions and 45 deletions
|
@ -15,11 +15,14 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
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.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
@ -37,7 +40,9 @@ import org.telegram.ui.ApplicationLoader;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -814,6 +819,28 @@ public class Utilities {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap getBitmap(final Uri uri){
|
||||||
|
Bitmap result = null;
|
||||||
|
ParcelFileDescriptor parcelFD = null;
|
||||||
|
try {
|
||||||
|
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
|
||||||
|
FileDescriptor fileDescriptor = parcelFD.getFileDescriptor();
|
||||||
|
result = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
} finally {
|
||||||
|
if (parcelFD != null)
|
||||||
|
try {
|
||||||
|
parcelFD.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isExternalStorageDocument(Uri uri) {
|
public static boolean isExternalStorageDocument(Uri uri) {
|
||||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -49,6 +50,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
private NotificationView notificationView;
|
private NotificationView notificationView;
|
||||||
private String photoPath = null;
|
private String photoPath = null;
|
||||||
|
private Bitmap sendingBitmap = null;
|
||||||
private String videoPath = null;
|
private String videoPath = null;
|
||||||
private String sendingText = null;
|
private String sendingText = null;
|
||||||
private int currentConnectionState;
|
private int currentConnectionState;
|
||||||
|
@ -217,7 +219,8 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
||||||
photoPath = (String)NotificationCenter.Instance.getFromMemCache(533);
|
photoPath = (String)NotificationCenter.Instance.getFromMemCache(533);
|
||||||
videoPath = (String)NotificationCenter.Instance.getFromMemCache(534);
|
videoPath = (String)NotificationCenter.Instance.getFromMemCache(534);
|
||||||
sendingText = (String)NotificationCenter.Instance.getFromMemCache(535);
|
sendingText = (String)NotificationCenter.Instance.getFromMemCache(535);
|
||||||
if (videoPath != null || photoPath != null || sendingText != null) {
|
sendingBitmap = (Bitmap)NotificationCenter.Instance.getFromMemCache(536);
|
||||||
|
if (videoPath != null || photoPath != null || sendingText != null || sendingBitmap != null) {
|
||||||
MessagesActivity fragment = new MessagesActivity();
|
MessagesActivity fragment = new MessagesActivity();
|
||||||
fragment.selectAlertString = R.string.ForwardMessagesTo;
|
fragment.selectAlertString = R.string.ForwardMessagesTo;
|
||||||
fragment.animationType = 1;
|
fragment.animationType = 1;
|
||||||
|
@ -310,10 +313,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
||||||
fragment.processSendingVideo(videoPath);
|
fragment.processSendingVideo(videoPath);
|
||||||
} else if (sendingText != null) {
|
} else if (sendingText != null) {
|
||||||
fragment.processSendingText(sendingText);
|
fragment.processSendingText(sendingText);
|
||||||
|
} else if (sendingBitmap != null) {
|
||||||
|
fragment.processSendingPhoto(sendingBitmap);
|
||||||
}
|
}
|
||||||
photoPath = null;
|
photoPath = null;
|
||||||
videoPath = null;
|
videoPath = null;
|
||||||
sendingText = null;
|
sendingText = null;
|
||||||
|
sendingBitmap = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1242,34 +1242,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String imageFilePath = null;
|
String imageFilePath = null;
|
||||||
if (imageUri.getScheme().contains("file")) {
|
Bitmap bitmap = Utilities.getBitmap(imageUri);
|
||||||
imageFilePath = imageUri.getPath();
|
processSendingPhoto(bitmap);
|
||||||
processSendingPhoto(imageFilePath);
|
|
||||||
} else if(imageUri.getScheme().contains("content")){
|
|
||||||
ParcelFileDescriptor parcelFD = null;
|
|
||||||
try {
|
|
||||||
parcelFD = parentActivity.getContentResolver().openFileDescriptor(imageUri, "r");
|
|
||||||
FileDescriptor fileDescriptor = parcelFD.getFileDescriptor();
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
|
||||||
processSendingPhoto(bitmap);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return;
|
|
||||||
} finally {
|
|
||||||
if (parcelFD != null)
|
|
||||||
try {
|
|
||||||
parcelFD.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
imageFilePath = Utilities.getPath(imageUri);
|
|
||||||
} catch (Exception e) {
|
|
||||||
FileLog.e("tmessages", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (requestCode == 2) {
|
} else if (requestCode == 2) {
|
||||||
String videoPath = null;
|
String videoPath = null;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
@ -52,25 +53,14 @@ public class LaunchActivity extends PausableActivity {
|
||||||
if (parcelable == null) {
|
if (parcelable == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String path = null;
|
Bitmap bitmap = null;
|
||||||
if (parcelable instanceof Uri) {
|
if (parcelable instanceof Uri) {
|
||||||
path = Utilities.getPath((Uri)parcelable);
|
bitmap = Utilities.getBitmap((Uri) parcelable);
|
||||||
} else {
|
} else {
|
||||||
path = intent.getParcelableExtra(Intent.EXTRA_STREAM).toString();
|
|
||||||
if (path.startsWith("content:")) {
|
|
||||||
Cursor cursor = getContentResolver().query(Uri.parse(path), new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.moveToFirst();
|
|
||||||
path = cursor.getString(0);
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (path != null) {
|
if (bitmap != null) {
|
||||||
if (path.startsWith("file:")) {
|
NotificationCenter.Instance.addToMemCache(536, bitmap);
|
||||||
path = path.replace("file://", "");
|
|
||||||
}
|
|
||||||
NotificationCenter.Instance.addToMemCache(533, path);
|
|
||||||
}
|
}
|
||||||
} else if (intent.getType().startsWith("video/")) {
|
} else if (intent.getType().startsWith("video/")) {
|
||||||
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
|
Loading…
Reference in a new issue