Jump to content
Aamgian

How Fetch SMS on Android and ios

Recommended Posts

Check this link: https://forums.embarcadero.com/thread.jspa?threadID=256233

 

This is a link to the demo I created: https://forums.embarcadero.com/thread.jspa?messageID=899142

 

Edit: Just realised you want it for 10.3.3. That old demo might still work, though. If not, I'll help modify it

 

Edit 2: Also now realised you want existing messages. Probably better to use the conversations class: https://developer.android.com/reference/android/provider/Telephony.Sms.Conversations. If the code on FMX Express does not work, please indicate what errors you're having. It may be that you just need to request the READ_SMS permission.

Edited by Dave Nottage
  • Thanks 1

Share this post


Link to post

Thank you Dave,

I am done with the Android code of, now I have not found a reference for iOS. the link above that you provide seems to be a problem with the web emb.


 

uses

Androidapi.helpers, Androidapi.JNI.GraphicsContentViewText,
Androidapi.jni.net, Androidapi.JNI.App, Androidapi.JNI.JavaTypes,


function FetchSms(sender:string):string;
var
  cursor: JCursor;
  uri: Jnet_Uri;
  address, msgdatesent, body: string;
  addressidx, msgdatesentidx, bodyidx: integer;
  fMessage: string;
begin
  uri := StrToJURI('content://sms/inbox');
  cursor := TAndroidHelper.Activity.getContentResolver.query(uri, nil, nil,nil,nil);
  addressidx := cursor.getColumnIndex(StringToJstring('address'));
  msgdatesentidx := cursor.getColumnIndex(StringToJstring('date_sent'));
  bodyidx := cursor.getColumnIndex(StringToJstring('body'));
  cursor.moveToFirst;
  while (cursor.moveToNext) do
  begin
    address := JStringToString(cursor.getString(addressidx));
    msgdatesent := JStringToString(cursor.getString(msgdatesentidx));
    body := JStringToString(cursor.getString(bodyidx));
    if UpperCase(address) = UpperCase(sender) then
    begin
      fMessage := msgdatesent+'-'+address+'-'+body;
      Break
    end;
  end;
  Result := fMessage;
end;

of course you must be given READ_SMS  permission.

Share this post


Link to post
50 minutes ago, Aamgian said:

now I have not found a reference for iOS.

That's because you cannot retrieve existing SMS messages on iOS - this is a privacy restriction from Apple. You cannot even intercept new messages.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×