From b1300a4416ad642f599647e8426d837cb1206064 Mon Sep 17 00:00:00 2001 From: Stanislav Silnicki Date: Sat, 30 May 2020 18:08:58 +0300 Subject: [PATCH] couple lines of comments on the case --- .../thoughtcrime/securesms/ShareActivity.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/ShareActivity.java b/src/org/thoughtcrime/securesms/ShareActivity.java index c3426d8dc..3b7236581 100644 --- a/src/org/thoughtcrime/securesms/ShareActivity.java +++ b/src/org/thoughtcrime/securesms/ShareActivity.java @@ -203,12 +203,50 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity implement 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) + if(contactId == 0) { contactId = dcContext.createContact(null, addr); + } chatId = dcContext.createChatByContactId(contactId); }