[File sharing] finish vcard sharing
This commit is contained in:
parent
b6f642a518
commit
f06de68fe1
4 changed files with 95 additions and 27 deletions
|
@ -91,7 +91,6 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -788,12 +787,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
if(path.contains("file://")) {
|
||||
path = path.substring(7);
|
||||
}else if(path.contains("com.android.contacts/contacts/")){
|
||||
Log.e("===>>> ChatFragment - sendFileSharingMessage : path = "+path);
|
||||
path = getCVSPathFromLookupUri(path).toString();
|
||||
}else if(path.contains(".vcf")){
|
||||
//TODO : do something
|
||||
} else if(path.contains("vcard") || path.contains("vcf")) {
|
||||
path = (LinphoneUtils.createCvsFromString(LinphoneActivity.instance().getCVSPathFromOtherUri(path).toString())).toString();
|
||||
}
|
||||
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();
|
||||
if(newChatConversation && chatRoom == null) {
|
||||
|
@ -943,34 +940,23 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
return null;
|
||||
}
|
||||
|
||||
public Uri getCVSPathFromLookupUri(Uri contentUri) {
|
||||
return getCVSPathFromLookupUri(contentUri.getPath());
|
||||
}
|
||||
|
||||
public Uri getCVSPathFromLookupUri(String content) {
|
||||
String contactId = LinphoneUtils.getNameFromFilePath(content);
|
||||
LinphoneFriend[] friendList = LinphoneManager.getLc().getFriendList();
|
||||
for(LinphoneFriend friend : friendList){
|
||||
if(friend.getRefKey().toString().equals(contactId)) {
|
||||
String contactVcard = friend.getVcardToString();
|
||||
Uri path = createCvsFromString(contactVcard, contactId);
|
||||
Uri path = LinphoneUtils.createCvsFromString(contactVcard);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Uri createCvsFromString(String vcardString, String contactId){
|
||||
File vcfFile = new File(Environment.getExternalStorageDirectory(), "contact-"+contactId+".cvs");
|
||||
try {
|
||||
FileWriter fw = new FileWriter(vcfFile);
|
||||
fw.write(vcardString);
|
||||
fw.close();
|
||||
return Uri.fromFile(vcfFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
public Uri getCVSPathFromLookupUri(Uri contentUri) {
|
||||
String content = contentUri.getPath();
|
||||
Uri uri = getCVSPathFromLookupUri(content);
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1142,7 +1128,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
String fileToUploadPath = null;
|
||||
if (data != null && data.getData() != null) {
|
||||
if(data.getData().toString().contains("com.android.contacts/contacts/")){
|
||||
fileToUploadPath = getCVSPathFromLookupUri(data.getData()).toString();
|
||||
if(getCVSPathFromLookupUri(data.getData()) != null)
|
||||
fileToUploadPath = getCVSPathFromLookupUri(data.getData()).toString();
|
||||
else {
|
||||
LinphoneActivity.instance().displayCustomToast("Something wrong happened", Toast.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
fileToUploadPath = getRealPathFromURI(data.getData());
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.app.Dialog;
|
|||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
@ -87,6 +88,9 @@ import org.linphone.ui.AddressText;
|
|||
import org.linphone.xmlrpc.XmlRpcHelper;
|
||||
import org.linphone.xmlrpc.XmlRpcListenerBase;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -670,7 +674,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
|||
}
|
||||
|
||||
if (currentFragment == FragmentsAvailable.CHAT_LIST || currentFragment == FragmentsAvailable.CHAT) {
|
||||
Log.e(" ===>>> displayChat : currentFragment = "+ currentFragment.toString());
|
||||
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
||||
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT && !emptyFragment) {
|
||||
ChatFragment chatFragment = (ChatFragment) fragment2;
|
||||
|
@ -1813,6 +1816,31 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getCVSPathFromOtherUri(String path) {
|
||||
Uri contactUri = Uri.parse(path);
|
||||
|
||||
ContentResolver cr = getContentResolver();
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = cr.openInputStream(contactUri);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringBuffer fileContent = new StringBuffer("");
|
||||
int ch;
|
||||
try {
|
||||
while( (ch = stream.read()) != -1)
|
||||
fileContent.append((char)ch);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String data = new String(fileContent);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface ContactPicked {
|
||||
|
|
|
@ -116,16 +116,13 @@ public class LinphoneLauncherActivity extends Activity {
|
|||
String type = intent.getType();
|
||||
newIntent.setData(intent.getData());
|
||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
Log.e("====>>> LinphoneLauncherActivity : onServiceReady - type = "+type);
|
||||
if (type.contains("text/")){ //&& intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
|
||||
|
||||
if(("text/plain").equals(type) && intent.getStringExtra(Intent.EXTRA_TEXT)!= null) {
|
||||
stringFileShared = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
Log.e("====>>> LinphoneLauncherActivity : onServiceReady - stringText = "+stringFileShared);
|
||||
newIntent.putExtra("msgShared", stringFileShared);
|
||||
} else if(((Uri) intent.getExtras().get(Intent.EXTRA_STREAM)) != null){
|
||||
stringFileShared = ((Uri) intent.getExtras().get(Intent.EXTRA_STREAM)).getPath();
|
||||
Log.e("====>>> LinphoneLauncherActivity : onServiceReady - stringFileShared = "+stringFileShared);
|
||||
stringFileShared = (LinphoneUtils.createCvsFromString(LinphoneUtils.processContactUri(getApplicationContext(), (Uri)intent.getExtras().get(Intent.EXTRA_STREAM)))).toString();
|
||||
newIntent.putExtra("fileShared", stringFileShared);
|
||||
}
|
||||
}else {
|
||||
|
|
|
@ -68,6 +68,7 @@ import java.io.FileDescriptor;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -873,5 +874,56 @@ public final class LinphoneUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String processContactUri(Context context, Uri contactUri){
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
InputStream stream = null;
|
||||
if(cr !=null) {
|
||||
try {
|
||||
stream = cr.openInputStream(contactUri);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(stream != null) {
|
||||
StringBuffer fileContent = new StringBuffer("");
|
||||
int ch;
|
||||
try {
|
||||
while ((ch = stream.read()) != -1)
|
||||
fileContent.append((char) ch);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String data = new String(fileContent);
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getContactNameFromVcard(String vcard){
|
||||
if(vcard != null) {
|
||||
String contactName = vcard.substring(vcard.indexOf("FN:") + 3);
|
||||
contactName = contactName.substring(0, contactName.indexOf("\n") - 1);
|
||||
contactName = contactName.replace(";", "");
|
||||
contactName = contactName.replace(" ", "");
|
||||
return contactName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Uri createCvsFromString(String vcardString){
|
||||
String contactName = getContactNameFromVcard(vcardString);
|
||||
File vcfFile = new File(Environment.getExternalStorageDirectory(), contactName+".cvs");
|
||||
try {
|
||||
FileWriter fw = new FileWriter(vcfFile);
|
||||
fw.write(vcardString);
|
||||
fw.close();
|
||||
return Uri.fromFile(vcfFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue