In Java, you can use Intent, but I did not find how to call another application, namely an email application. Call from your application by button.

  • Android application? - αλεχολυτ
  • @alexolut cross-platform application, under android respectively too - Uliyan Romanov

2 answers 2

You need to invoke the Java code from C ++ using the JNI tools. For example:

Java

package com.package; class PlatformUtils { public static final void openEmailClient(final String address, final String subject, final String text) { // mailto:[ mail address ] [?] [subject=subject] [&cc=mail address] [&bcc=mail address] [&body=message body] String URI = ("mailto:" + (address == null ? "" : URLEncoder.encode(address, "utf-8").replace("+", "%20"))); URI += ("?subject=" + (subject == null ? "" : URLEncoder.encode(subject, "utf-8").replace("+", "%20"))); URI += ("&body=" + (text == null ? "" : URLEncoder.encode(text, "utf-8").replace("+", "%20"))); final Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); Uri data = Uri.parse(URI); intent.setData(data); context.startActivity(intent); } } 

C ++

 void openEmailClient(const char* address, const char* subject, const char* text) { JNIEnv* env = DGetJNIEnv(); jclass cls = env->FindClass("com/package/PlatformUtils"); if(cls) { jmethodID meth = env->GetStaticMethodID(cls, "openEmailClient", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); if(meth) { jstring param_address = env->NewStringUTF(address == null ? "" : address); jstring param_subject = env->NewStringUTF(subject == null ? "" : subject); jstring param_text = env->NewStringUTF(text == null ? "" : text); env->CallStaticVoidMethod(cls, meth, param_address, param_subject, param_text); } } } 
  • jclass cls = env->FindClass("com/package/PlatformUtils"); The specific path in the folder with the project should be specified? - Uliyan Romanov
  • @UliyanRomanov is the full name of the java-class with the package. In the example, this is com.package.PlatformUtils. In FindClass, dots are replaced by slashes. - RuslanK
  • DGetJNIEnv (); - I have no such method - Uliyan Romanov
  • @UliyanRomanov I don’t know your compiler bundle, but usually #include "jni.h" helps. - RuslanK
  • This may seem ridiculous, but what is a context? We intellij IDEA offers to initialize null this. Without context, startactivity will be underlined. I used a shorter method, but there is such an if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); getPackageManager() and startActivity(intent) underlines. Do not pay attention to this? - Uliyan Romanov

The same intent and use

http://blong.com/Articles/DelphiXE5AndroidActivityResult/ActivityResult.htm#EmailActivity

https://stackoverflow.com/questions/28956563/how-to-send-email-with-attachment-using-default-android-email-app-delphi-xe7

 uses Androidapi.JNIBridge, ... ... procedure CreateEmail(const Recipient, Subject, Content: string); overload; var Intent: JIntent; begin Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_SEND); Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, StringToJString(Recipient)); Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject)); Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content)); // Intent.setType(StringToJString('plain/text')); Intent.setType(StringToJString('message/rfc822')); // LaunchActivity(Intent); LaunchActivity(TJIntent.JavaClass.createChooser(Intent, StrToJCharSequence('Which email app?'))); end; 

Only on pluses from Pascal rewrite. You are not used to the builder))