Merge pull request #1342 from mailgate/master

simple solution to open chat & put an attachement from external app...
This commit is contained in:
bjoern
2020-06-14 13:16:11 +02:00
committed by GitHub
@@ -201,6 +201,55 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity implement
private void handleResolvedMedia(Intent intent) {
int chatId = intent.getIntExtra(EXTRA_CHAT_ID, -1);
String[] extraEmail = getIntent().getStringArrayExtra(Intent.EXTRA_EMAIL);
/*
usually, external app will try to start "e-mail sharing" intent, providing it:
1. address(s), packed in array, marked as Intent.EXTRA_EMAIL - mandatory
2. shared content (files, pics, video), packed in Intent.EXTRA_STREAM - optional
here is a sample code to trigger this routine from within external app:
try {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "someone@example.com", null));
File f = new File(getFilesDir() + "/somebinaryfile.bin");
f.createNewFile();
f.setReadable(true, false);
byte[] b = new byte[1024];
new Random().nextBytes(b);
FileOutputStream fOut = new FileOutputStream(f);
DataOutputStream dataStream = new DataOutputStream(fOut);
dataStream.write(b);
dataStream.close();
Uri sharedURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", f);
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"someone@example.com"});
emailIntent.setType("text/plain");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.putExtra(Intent.EXTRA_STREAM, sharedURI);
// to EXPLICITLY fire DC's sharing activity:
// emailIntent.setComponent(new ComponentName("com.b44t.messenger.beta", "org.thoughtcrime.securesms.ShareActivity"));
startActivity(emailIntent);
} catch (IOException e) {
e.printStackTrace();
}catch (ActivityNotFoundException e) {
}
*/
if(chatId == -1 && extraEmail != null && extraEmail.length > 0) {
final String addr = extraEmail[0];
int contactId = dcContext.lookupContactIdByAddr(addr);
if(contactId == 0) {
contactId = dcContext.createContact(null, addr);
}
chatId = dcContext.createChatByContactId(contactId);
}
Intent composeIntent = getBaseShareIntent(ConversationListActivity.class);
RelayUtil.setSharedUris(composeIntent, resolvedExtras);
if (chatId != -1) {
@@ -249,4 +298,4 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity implement
return "file".equals(uri.getScheme());
}
}
}