Ask for external file storage permission for Android 6+ when a file transfer message is received or when attemping to download it
This commit is contained in:
parent
043da11d26
commit
320757c24a
3 changed files with 33 additions and 9 deletions
|
@ -38,6 +38,7 @@ import org.linphone.core.LinphoneCoreListenerBase;
|
|||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.BubbleChat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
@ -45,6 +46,7 @@ import android.app.Fragment;
|
|||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -218,6 +220,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
if (from.asStringUriOnly().equals(sipUri)) {
|
||||
invalidate();
|
||||
messagesList.setSelection(adapter.getCount()-1);
|
||||
|
||||
String externalBodyUrl = message.getExternalBodyUrl();
|
||||
LinphoneContent fileTransferContent = message.getFileTransferInformation();
|
||||
if (externalBodyUrl != null || fileTransferContent != null) {
|
||||
LinphoneActivity.instance().checkAndRequestExternalStoragePermission();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 200;
|
||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO_INCOMING_CALL = 203;
|
||||
private static final int PERMISSIONS_REQUEST_EXTERNAL_FILE_STORAGE = 204;
|
||||
|
||||
private static LinphoneActivity instance;
|
||||
|
||||
|
@ -1196,6 +1197,12 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
getIntent().putExtra("PreviousActivity", 0);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public void checkAndRequestExternalStoragePermission() {
|
||||
if (getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getPackageName()) != PackageManager.PERMISSION_GRANTED) {
|
||||
checkAndRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSIONS_REQUEST_EXTERNAL_FILE_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkAndRequestPermission(String permission, int result) {
|
||||
if (getPackageManager().checkPermission(permission, getPackageName()) != PackageManager.PERMISSION_GRANTED) {
|
||||
|
|
|
@ -26,8 +26,10 @@ import java.util.Calendar;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.linphone.LinphoneActivity;
|
||||
import org.linphone.LinphoneContact;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphonePreferences;
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneBuffer;
|
||||
|
@ -36,9 +38,11 @@ import org.linphone.core.LinphoneChatMessage.State;
|
|||
import org.linphone.core.LinphoneContent;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -138,7 +142,7 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
|
|||
LinphoneManager.addListener(this);
|
||||
}
|
||||
|
||||
if (externalBodyUrl != null || fileTransferContent != null ) {
|
||||
if (externalBodyUrl != null || fileTransferContent != null) {
|
||||
String appData = message.getAppData();
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.image);
|
||||
|
||||
|
@ -167,14 +171,19 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
|
|||
acceptDownload.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
v.setEnabled(false);
|
||||
String filename = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()));
|
||||
File file = new File(Environment.getExternalStorageDirectory(), filename);
|
||||
nativeMessage.setAppData(filename);
|
||||
LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage);
|
||||
nativeMessage.setListener(LinphoneManager.getInstance());
|
||||
nativeMessage.setFileTransferFilepath(file.getPath());
|
||||
nativeMessage.downloadFile();
|
||||
if (mContext.getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
|
||||
v.setEnabled(false);
|
||||
String filename = context.getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis()));
|
||||
File file = new File(Environment.getExternalStorageDirectory(), filename);
|
||||
nativeMessage.setAppData(filename);
|
||||
LinphoneManager.getInstance().addDownloadMessagePending(nativeMessage);
|
||||
nativeMessage.setListener(LinphoneManager.getInstance());
|
||||
nativeMessage.setFileTransferFilepath(file.getPath());
|
||||
nativeMessage.downloadFile();
|
||||
} else {
|
||||
Log.w("WRITE_EXTERNAL_STORAGE permission not granted, won't be able to store the downloaded file");
|
||||
LinphoneActivity.instance().checkAndRequestExternalStoragePermission();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue