Android Question SOLVED Use context in inline Java.

moster67

Expert
Licensed User
Longtime User
Ciao,
If you make a question and then you resolve it by yourself, I think it would be useful if you also post the solution.
This will help other users who might be having the same problem/question and it will probably show up in the search-engine of the forum.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
You are right, forgive me!
in bold there is the answer to my silly question... This code deletes a SMS received from a single number(numero) with a body content (messaggio), but only in pre KitKat:(...
in code bold doesn't work: the code is processBA.context
B4X:
Sub chiamajava
    Dim messaggio As String="Test"
    Dim numero As String="+3934XXXXXXX"
    native.RunMethod("deleteSMS",Array(messaggio, numero))
End Sub
#if JAVA
import android.net.Uri;
import android.database.Cursor;
import anywheresoftware.b4a.keywords.Common;
public void deleteSMS( String message, String number) {
            Common.Log("Messaggio:" + message);
            Common.Log("Numero:" + number);
            Uri uriSms = Uri.parse("content://sms");
         
            Cursor c = processBA.context.getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", "person", "date", "body" }, null, null, null);


               if(c==null)
                {
                 return;
                }
                c.moveToFirst();
                do {
                    long id = c.getLong(0);
                    long threadId = c.getLong(1);
                    String address = c.getString(2);
                    String body = c.getString(5);
                    String date = c.getString(3);
        
                    Common.Log(address);
                    Common.Log(body);
                    if (message.equals(body) && address.equals(number)) {
                        Common.Log("Deleting SMS with id: " + threadId);
                        int rows = processBA.context.getContentResolver().delete(Uri.parse("content://sms/" + id), "date=?",new String[] { c.getString(4) });
                   }                     
                } while (c.moveToNext());
         
         }
#End If
 
Last edited:
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thank you and this is not a silly question. Many people are asking about javaobject and inline java:)
I am sure will be useful for someone.
 
Upvote 0
Top