Deep Android integration

Hello! is it possible to start DC from other Android app in particular chat?
Say, I’d like to use DC for easy integration of tech support within my app, just opening it once user needs to chat with support. If so, which activity is the right one to stick to?

… it appears that DC has a limitation on the Intents it receives and process…

Sending with MAILTO Intent is possible and directly to required address, while it is not possible to attach a file…

The below code correctly formats MAILTO Intent including both sendto address and an attachement:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( “mailto”, “”, null));
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.putExtra(Intent.EXTRA_STREAM, sharedURI);
emailIntent.setType(“text/plain”);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(emailIntent);

I have tested couple apps correctly parsing such Intent (Gmail, BlueMail)

As for DC4Android, it is missing couple lines of code within .ShareActivity I beleive, as it correctly parses the attachment, while doesn’t select proper chat (as opposite to .NewConversationActivity, which does select proper chat, while doesn’t accept an attachment).

I think its worth fixing it somehow…

simple solution posted for review at github…

1 Like

ok, here is complete example, working with this proposal: https://github.com/deltachat/deltachat-android/pull/1342

        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);

            // it will try to start BETA package, so only for development purposes!
            emailIntent.setComponent(new ComponentName("com.b44t.messenger.beta", "org.thoughtcrime.securesms.ShareActivity"));

            startActivity(emailIntent);
        } catch (IOException e) {
            e.printStackTrace();
        }catch (ActivityNotFoundException e) {
            //TODO: Handle case where no email app is available
        }

hi @stan - first of all, welcome aboard!

great, that you have done directly a pull request for your suggestion, this is very welcome :slight_smile:

i think someone from the dev team will have a closer look at this one of the next days, currently, afaik, everyone is struggling with other things :wink:

btw, if you like, most devs are also hanging on on irc freenode #deltachat - it is not always busy there, but from time to time - and by the “mornings” or “moin” one gets an idea who is online :slight_smile:

best -
bjoern

Great! I’ll give #deltachat a try. I’d be happy to volunteer for delta.chat when not busy on my primary project :slight_smile:

DC is great product and I wish it luck and success!

2 Likes

@stan i finally merged your pull request in, so it should be available in the next nightly and also in the upcoming releases :slight_smile: thanks again - and sorry for the delays.

My pleasure to be helpful and contribute this beautiful project! It is great collaboration experience for me.

5 Likes