While searching the internet I came across the topic of sending SMS but unfortunately I did not find any example for C ++ Builder. Everything is written in Delphi. I tried to rewrite the instructions in C ++ and got this code:
#include <Androidapi.Helpers.hpp>
#include <Androidapi.JNI.JavaTypes.hpp>
#include <Androidapi.JNI.Telephony.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNI.App.hpp>
#include <Androidapi.JNI.Net.hpp>
JString* wiadomosc = StringToJString( L"Wiadomość" );
Jnet_Uri* URI;
JString* destAdress;
URI = StrToJURI( "12345678" ); // phone number
_di_JIntent Intent = TJIntent::JavaClass->init( TJIntent::JavaClass->ACTION_VIEW, URI ); //ACTION_VIEW ACTION_SEND
Intent->setType( StringToJString("text/plain") );
//Intent->putExtra( TJIntent::JavaClass->EXTRA_TEXT, wiadomosc ); StringToJString('sms_body')
Intent->putExtra( StringToJString("sms_body"), wiadomosc );
::SharedActivityContext()->startActivity( Intent );
//SharedActivity()->startActivity(Intent);
该程序有效但不像我预期的那样。出现应用程序选择窗口,尽管将永久短信设置为默认设置,但即使代码中存在该数据,我也无法在不输入电话号码和短信的情况下发送短信。请给我提示如何在不使用 Android 上的默认程序的情况下发送短信。
我想你会很难找到这方面的帮助——C++ builder 已经是一小部分用户,那些在 Android 上使用它的用户还很少(我已经做 Android 7 年了,这是我第一次使用甚至听说过它)。如果您直接使用 NDK,您更有可能找到帮助。但我可以告诉你 NDK/Java 的方式是使用 SMSManager。像您一样使用意图将始终启动默认应用程序。
您可以发布指向 Delphi 代码的链接以进行比较吗?我已经多年没有使用 C++ Builder,但我将永远对它情有独钟!
我也试过这样做:JSmsManager* smsManager; JString* smsTo; // smsManager=JSmsManager::JavaClass->getDefault; smsTo=StringToJString("12345678"); smsManager->sendTextMessage(smsTo, NULL, StringToJString("The message content"), NULL, NULL);但有错误:“Exception class Segmentation fault (11), rhs->AddRef();”
@BareMetalCoder stackoverflow.com/questions/39762688/…
@JacekRogowski:在 C++Builder 中,您必须为 Delphi 风格的接口使用 Delphi 风格的接口包装类,而不是原始接口指针,例如:_di_JSmsManager smsManager=TJSmsManager::JavaClass->getDefault(); _di_JString smsTo=StringToJString(L"12345678"); smsManager->sendTextMessage(smsTo, nullptr, StringToJString(L"The message content"), nullptr, nullptr);