Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
int i=0;
while (cur.moveToNext()) {
Phone_no=cur.getString(2);
Time=cur.getLong(4);
Message_body=cur.getString(11);
Date dateObj = new Date(Time);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
String Timenew = df.format(dateObj);
Log.d(Tag,"INSIDE OF READ SMS INBOX");
service.setClass(getBaseContext(), Background_Service.class);
service.putExtra("Phone_no", Phone_no);
service.putExtra("Message_body", Message_body);
service.putExtra("Timenew", Timenew);
getBaseContext().startService(service);
}
the above code read the message from the inbox. And i send those message to the service for further processing. Is this the right way to do. Should i create a queue for the service execution, if so how to create, implement a queue to the above code.
Yes, it is applicable way.
But, i prefer another one.
Instead of starting a new service and routing new intents to it, you can create service once and bind to it, and send
Messages to it.First of all you need a messaging protocol. The easiest way it is create AIDL file with similar content.
And then, you must implement it in your service.
And then, you must connect to your service.
There are more on this topic.