mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-31 16:40:45 +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.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Html;
|
||||
|
@ -37,7 +40,9 @@ import org.telegram.ui.ApplicationLoader;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
@ -814,6 +819,28 @@ public class Utilities {
|
|||
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) {
|
||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.app.NotificationManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -49,6 +50,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
private boolean finished = false;
|
||||
private NotificationView notificationView;
|
||||
private String photoPath = null;
|
||||
private Bitmap sendingBitmap = null;
|
||||
private String videoPath = null;
|
||||
private String sendingText = null;
|
||||
private int currentConnectionState;
|
||||
|
@ -217,7 +219,8 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
photoPath = (String)NotificationCenter.Instance.getFromMemCache(533);
|
||||
videoPath = (String)NotificationCenter.Instance.getFromMemCache(534);
|
||||
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();
|
||||
fragment.selectAlertString = R.string.ForwardMessagesTo;
|
||||
fragment.animationType = 1;
|
||||
|
@ -310,10 +313,13 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
|
|||
fragment.processSendingVideo(videoPath);
|
||||
} else if (sendingText != null) {
|
||||
fragment.processSendingText(sendingText);
|
||||
} else if (sendingBitmap != null) {
|
||||
fragment.processSendingPhoto(sendingBitmap);
|
||||
}
|
||||
photoPath = null;
|
||||
videoPath = null;
|
||||
sendingText = null;
|
||||
sendingBitmap = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1242,34 +1242,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
return;
|
||||
}
|
||||
String imageFilePath = null;
|
||||
if (imageUri.getScheme().contains("file")) {
|
||||
imageFilePath = imageUri.getPath();
|
||||
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);
|
||||
}
|
||||
}
|
||||
Bitmap bitmap = Utilities.getBitmap(imageUri);
|
||||
processSendingPhoto(bitmap);
|
||||
} else if (requestCode == 2) {
|
||||
String videoPath = null;
|
||||
if (data != null) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.app.NotificationManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
@ -52,25 +53,14 @@ public class LaunchActivity extends PausableActivity {
|
|||
if (parcelable == null) {
|
||||
return;
|
||||
}
|
||||
String path = null;
|
||||
Bitmap bitmap = null;
|
||||
if (parcelable instanceof Uri) {
|
||||
path = Utilities.getPath((Uri)parcelable);
|
||||
bitmap = Utilities.getBitmap((Uri) parcelable);
|
||||
} 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 (path.startsWith("file:")) {
|
||||
path = path.replace("file://", "");
|
||||
}
|
||||
NotificationCenter.Instance.addToMemCache(533, path);
|
||||
if (bitmap != null) {
|
||||
NotificationCenter.Instance.addToMemCache(536, bitmap);
|
||||
}
|
||||
} else if (intent.getType().startsWith("video/")) {
|
||||
Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
|
|
Loading…
Reference in a new issue