Android Question Read MessageSent

PoleStar

Member
Licensed User
Longtime User
Hi My Friends
All of us have worked SmsInterceptor.
But SmsInterceptor Just Read MessageReceived.
I was To Read MessageSent.
This means that as soon as the user to send SMS messages,
I can get text message and phone number of the recipient of the text message.

Excuse me if I have a problem in the English language and I work with Google Translator

Please Help Me
Thanks a lot
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
B4X:
Sub youreventname_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
If Success then
log("Sent succefully")
else
log(ErrorMessage )
end if
End sub
 
Upvote 0

PoleStar

Member
Licensed User
Longtime User

Thanks
But this event just working when i using PhoneSms for send message.
If user send message with default android sms sender this event not working
I tested it
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thanks
But this event just working when i using PhoneSms for send message.
If user send message with default android sms sender this event not working
I tested it
B4X:
Sub Process_Globals
  Private cr As ContentResolver
End Sub

Sub Service_Create
  Dim uri As Uri
  uri.Parse("content://sms/out")
  cr.Initialize("cr")
  cr.RegisterObserver(uri, True)
End Sub

Sub cr_ObserverChange (Uri As Uri)
  Log("SMS Change "& Uri)
End Sub

Not tested I took information from here http://stackoverflow.com/a/7790755

And B4A Observer from here
https://www.b4x.com/android/help/contentresolver.html#contentresolver_registerobserver
You might want to check if it works and modify it

EDIT : After testing , it seems RegisterObserver has been removed
 
Last edited:
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Got this from here https://www.b4x.com/android/forum/t...-to-contentobserver-in-b4a.32051/#post-187303 and modified it till I was sure it will not work

B4X:
package smm.outsms;

import anywheresoftware.b4a.BA;

import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
import android.net.Uri;
import android.database.ContentObserver;
import android.os.Handler;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.content.ContentResolver;
@ShortName("SMSObserver")
@Events(values={"smssent(smsid as int)"})
@Permissions(values={"android.permission.READ_SMS"})

public class smmsms {
   
    private BA ba;
    private String eventName;
   
    public void Initialize(BA ba,String EventName) {
        _initialize(ba , EventName);
    }

    @Hide
    public void _initialize(BA ba, String EventName) {
        this.eventName = EventName.toLowerCase(BA.cul);
        this.ba = ba;
       
       
       
       
    }

   
   
    public void ListenToOutgoingMessages() {
       final Uri content = Uri.parse("content://sms");
       ContentObserver co = new ContentObserver(new Handler()) {
         @Override
        public void onChange(boolean selfChange) {
        super.onChange(selfChange);
       
        Cursor cursor = BA.applicationContext.getContentResolver().query(
               content,null, null, null, null);
           if (cursor.moveToNext()) {
             String protocol = cursor.getString(cursor.getColumnIndex("protocol"));
             int type = cursor.getInt(cursor.getColumnIndex("type"));
             String body =cursor.getString(cursor.getColumnIndex("body"));
             if (protocol != null || type != 2) {
              return;
             }//
        // ba.Log("OnChange"+body);
          ba.raiseEvent(null, eventName + "_smssent",cursor.getInt(cursor.getColumnIndex(BaseColumns._ID)) );
             cursor.close();
           }
        }
       };
       ContentResolver contentResolver = BA.applicationContext.getContentResolver();
       contentResolver.registerContentObserver(content, true, co);
     }

}
 

Attachments

  • SMSListener.zip
    2.7 KB · Views: 300
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…