[FileSharing] update sharing on multi devices

This commit is contained in:
Brieuc Viel 2017-08-16 13:50:17 +02:00
parent 7c1a764c73
commit c5b180b952
2 changed files with 36 additions and 16 deletions

View file

@ -753,6 +753,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
path = path.substring(7); path = path.substring(7);
Log.e("===>>> path replaced = "+path); Log.e("===>>> path replaced = "+path);
} }
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();
Log.e("====>>> ChatFragment - sendImageMessage() : newChatConversation = "+ newChatConversation +" - chatRoom = "+chatRoom); Log.e("====>>> ChatFragment - sendImageMessage() : newChatConversation = "+ newChatConversation +" - chatRoom = "+chatRoom);

View file

@ -19,11 +19,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package org.linphone; package org.linphone;
import android.app.Activity; import android.app.Activity;
import android.content.CursorLoader;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.provider.MediaStore;
import org.linphone.assistant.RemoteProvisioningActivity; import org.linphone.assistant.RemoteProvisioningActivity;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
@ -110,8 +113,8 @@ public class LinphoneLauncherActivity extends Activity {
public void run() { public void run() {
Intent newIntent = new Intent(LinphoneLauncherActivity.this, classToStart); Intent newIntent = new Intent(LinphoneLauncherActivity.this, classToStart);
Intent intent = getIntent(); Intent intent = getIntent();
String msgShared = null; String stringFileShared = null;
Uri imageUri = null; Uri fileUri = null;
if (intent != null) { if (intent != null) {
String action = intent.getAction(); String action = intent.getAction();
String type = intent.getType(); String type = intent.getType();
@ -119,16 +122,20 @@ public class LinphoneLauncherActivity extends Activity {
if (Intent.ACTION_SEND.equals(action) && type != null) { if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type) && intent.getStringExtra(Intent.EXTRA_TEXT) != null) { if ("text/plain".equals(type) && intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
Log.e(" ====>>> type = "+type+" share msg"); Log.e(" ====>>> type = "+type+" share msg");
msgShared = intent.getStringExtra(Intent.EXTRA_TEXT); stringFileShared = intent.getStringExtra(Intent.EXTRA_TEXT);
newIntent.putExtra("msgShared", msgShared); newIntent.putExtra("msgShared", stringFileShared);
}else if ( type.contains("image") ){ }else {//if ( type.contains("image") ){
msgShared = intent.getStringExtra(Intent.EXTRA_STREAM); if(intent.getStringExtra(Intent.EXTRA_STREAM) != null){
imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); stringFileShared = intent.getStringExtra(Intent.EXTRA_STREAM);
Log.e(" ====>>> type = "+type+" share images msgShared = "+msgShared +" VS toPath() = "+imageUri.getPath()); }else {
newIntent.putExtra("fileShared", imageUri.getPath()); fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
}else{ stringFileShared = getRealPathFromURI(fileUri);
}
Log.e(" ====>>> type = "+type+" share images msgShared = "+getRealPathFromURI(fileUri) +" VS toPath() = "+fileUri.getPath());
newIntent.putExtra("fileShared", stringFileShared);
}/*else{
Log.e(" ====>>> type = "+type+" share something else"); Log.e(" ====>>> type = "+type+" share something else");
} }*/
} }
} }
if (uriToResolve != null) { if (uriToResolve != null) {
@ -142,13 +149,13 @@ public class LinphoneLauncherActivity extends Activity {
addressToCall = null; addressToCall = null;
} }
startActivity(newIntent); startActivity(newIntent);
if (classToStart == LinphoneActivity.class && LinphoneActivity.isInstanciated() && (msgShared != null || imageUri != null)) { if (classToStart == LinphoneActivity.class && LinphoneActivity.isInstanciated() && (stringFileShared != null || fileUri != null)) {
if(msgShared != null) { if(stringFileShared != null) {
LinphoneActivity.instance().displayChat(null, msgShared, null); LinphoneActivity.instance().displayChat(null, stringFileShared, null);
} }
if(imageUri != null) { if(fileUri != null) {
LinphoneActivity.instance().displayChat(null, null, imageUri.toString()); LinphoneActivity.instance().displayChat(null, null, fileUri.toString());
} }
} }
finish(); finish();
@ -156,6 +163,18 @@ public class LinphoneLauncherActivity extends Activity {
}, 1000); }, 1000);
} }
public String getRealPathFromURI(Uri contentUri) {
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
if (cursor != null && cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String result = cursor.getString(column_index);
cursor.close();
return result;
}
return null;
}
private class ServiceWaitThread extends Thread { private class ServiceWaitThread extends Thread {
public void run() { public void run() {