rajeevs1992 / cordova-sms-reader

A simple to use, minimal frills SMS reader for cordova applications.
Other
7 stars 10 forks source link

Read SMS sent #3

Open J4YF7O opened 4 years ago

J4YF7O commented 4 years ago

Hello,

First of all, thank's for this very useful lib. I use the library in order to read all the sms received AND sent by the user. Unfortunately, using getAllSMS() I only get the sms I received, but never the sms sent.

Is this normal comportment for the plugin ?

J4YF7O

rajeevs1992 commented 4 years ago

Hi,

The plugin does not support reading of other folders as of now, as IMHO, it is not a very common use case. My primary goal was to keep the plugin as simple as possible, and hence read only inbox.

J4YF7O commented 4 years ago

Thank you for your answer, but why don't you look for the messages in content://sms/ rather than only in Inbox? I probably don't know enough about native Android.

rajeevs1992 commented 4 years ago

Hi, As I mentioned, it was my assumption that it was the most common use case. However, it won't be much difficult to modify the plugin to look whatever folders you need like content://sms/sent.To read all messages, you would need to use some thing like content://sms/all

J4YF7O commented 4 years ago

I just tried with content://sms/, but it was not possible to identify the status of the message: "sent / received". So I added a "type" attribute to the SMS class, which when creating the object takes the value of "type" in the cursor, which allows us to know a little more about the message.

// Change in SMS.java
// Line 12 (attributs declaration)
public int type;
// Line 20 (constructor)
        this.type = cursor.getInt(cursor.getColumnIndexOrThrow("type"));
// Line 58 (writeJSON)
        sms.put("type", this.type);

For my use case, I really need all the messages, and this may be enough. Would you like me to collaborate and extend the functionality of your library creating a pull request, or would you prefer me to fork it?

rajeevs1992 commented 4 years ago

I would be glad to accept a PR with the functionality. I would expose a new action on the js and java APIs that would accept the sms folder type string as a parameter, something likefetchSmsByFolderType(action, foldertype, since, searchtexts, senderids, permissions), rather than modifying/breaking the existing APIs. Please let me know if you will be able to complete the same, or need any assistance.

ref Folder types

J4YF7O commented 4 years ago

Hey,

Sorry I've had a lot of work in the meantime, and I've been able to move forward with my fix described above.

So, Today I fork the project, and do some update.

I'll explain my approach, I'll let you judge if it's the right one or not...

Only Rajeevs can judge me 😄

Reminder :

  • The result of the following js methods shall not be altered : getAllSMS, and filter*

Javascript

Steps

  1. I redefine the fetchSms() signature and add the foldertype (string) parameter, which is set to '' by default.
  2. I create a fetchSmsInbox() function, which calls the fetchSms() function with folderType set to inbox. getAllSMS, and filter*no longer call the fetchSms() function, but fetchSmsInbox().
  3. I create getSmsFromFolder(folderType, since), which allows to receive sms from the folder passed in parameter.
  4. I create "getSmsAll" which allows to receive sms from the folder : all ('').
  5. I create "getSmsInbox" which allows to receive sms from the folder : inbox. [questionable] : So I change getAllSms to deprecated.

More (TS)

I am a typescript user, so I took the liberty of adding an index.d.ts file for the type definition.

Java

SMS

Look at my last message.

SMSReader

  1. Add folderType param for fetchSMS method. With this value you can concatenate the sms address. (message)
  2. Update execute method : de la méthode "execute" to include support for the "folderType" parameter. I allowed myself to redefine the code structure a little bit.
    • Instead of including the "permission" action in the switch, I exclude it in a first "if". This allows me to define once and for all the variables sent by the JS array in other cases than "permission". In my case, I put "folderType" as the first parameter of the javascript table, because it is essential. Having variables well defined before the switch will allow us (maybe) later to add other parameters without having to change anything else than the index of variables already defined.

PS : Your Folder type reference is bad (or not working on my Android 10) : There are no content://sms/**all** To get all sms you have to call the empty folder type content://sms/.