Not able to read Service messages using READ_SMS permission android - android

We have an Android app where we are trying to read all the messages available in the phone. We are using READ_SMS permission but we are not able to read service messages in this way. By service mesaage I mean the messages obtained from different companies. For example I have messages in my phone from Amazon and Paytm but I am not able to load these while loading messages. I don't understand the issue. Is there any default filter that android is applying when the SMS get loaded or is there any issue with the code?
I use the following code to load all SMS:
private ArrayList load_sms(){
ContentResolver contentResolver = getContentResolver();
ArrayList<String> smsList = new ArrayList<>();
Cursor smsInboxCursor =
contentResolver.query(Uri.parse("content://sms/inbox"),
null,null,null,null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if(indexBody < 0 || !smsInboxCursor.moveToFirst())
return null;
do{
smsList.add("SMS From: " +
smsInboxCursor.getString(indexAddress) + " \nMessage: "
+ smsInboxCursor.getString(indexBody));
}while (smsInboxCursor.moveToNext());
return smsList;
}

So, the solution was quite vague. I have a MI phone and found that MI blocks service messages. To view those SMS' I had to give the permission manually from settings as given in this link: Can't read service messages in Redmi Note 3
When I ran my app on some other phone like in Samsung, I was able to view all the messages.

Related

How to Delete sent SMS with limit more than 500 android?

I followed this to Delete SMS..
So here I am using these
mContext.getContentResolver().delete(Uri.parse("content://sms/"), null, null);
I have a SMS sending app It sends more than 1k messages every hour
Now the problem is that In new/big phone its working fine, But when I installed same in a basic android phone with less internal memory / less SMS storage, I am facing NO_PDU error
So I want to delete it programmatically, but with LIMIT 500 sms or past 1 day sms or past 1 hr SMS.
mContext.getContentResolver().delete(Uri.parse("content://sms/"), null, null);
The above code will delete all the sms present in SmsProvider . To delete specific sms query SmsProvider and do your operation on selected rows.
Refer below example-
if (values.getAsInteger(Sms.TYPE) == Sms.MESSAGE_TYPE_DRAFT) {
SqliteDatabase.delete(TABLE_SMS, "thread_id=? AND type=?",
new String[] { values.getAsString(Sms.THREAD_ID),
Integer.toString(Sms.MESSAGE_TYPE_DRAFT) });
}

Android - Is it possible to have a content provider of hardware interacting methods?

The company I work for is made a custom piece of hardware that runs Android. It will be connected to quite a few peripheral components. A key point is that this device is for another company.
I know with a ContentProvider, data can be shared between applications. However, what I am wondering is whether methods that interact with the hardware (GPIO interaction) can be stored in some way that they can be used by any application.
For example, say the device has a certain GPIO pin mapped to an LED. You create a method that makes the LED flash, you use it in your application, then give the device to someone else and want the code hidden but use the LED flashing method again. This is not necessary but could allow the other company to build another app complementing the one we provide with the device.
Any insight would helpful.
Cheers
You can use ContentProvider like a REST webinterface
From apps:
Uri ledUri = Uri.parse("content://your.app/led");
ContentResolver cr = getContentResolver();
// "write" data
ContentValues cv = new ContentValues();
cv.put("state", 1);
cr.insert(ledUri, cv);
// read data
int newState = 0;
Cursor c = cr.query(ledUri, new String[] { "state" }, null, null, null);
if (c.moveToFirst()) {
newState = c.getInt(0);
}
Inside your provider, instead of writing data into a database you simply set / read GPIO states. Roughly like
#Override
public Uri insert(Uri uri, ContentValues values) {
if (uri.toString().equals("content://your.app/led")) {
int requestedState = values.getAsInteger("state");
set_gpio_state(requestedState);
}
}
How to acccess GPIOs from Java is another question since they are (AFAIK) only accessible on kernel level.

Android app using Google calendar - Sync issue

I am trying to create an android app that interfaces with the Google Calendar.
I have followed the tutorial using content providers from here. Parts of this code are explained here.
I am facing the below issues.
I created a new calendar TestCalendar from my online from my laptop, and marked it as Selected. When I query for my calendars from the app, I can see this new calendar, but it is shown as unselected (selected=0). Any suggestions on why this could be happening ?
From my app, I add an event to the calendar by
getContentResolver().insert(eventsUri, event);
The event is reflected in the calendar on phone, but it is not reflected in the online version. To push this new event online, I have to manually Synchronize the calendar, or turn the Auto Sync on, which I believe is not the right way in which this should be done. Any suggestions/links which could help ?
1) Can you dump your calendar and post the result?
Notice:
Android < API Lvl 14 you must set selected = 1
Android > API Lvl 14 you must set visible = 1 (selected is not longer available)
Dump:
cursor = contentResolver.query(Uri.parse(CALENDAR_URI),null, null, null,null);
while (cursor.moveToNext()) {
for (int i = 0; i < cursor.getColumnCount(); i++) {
Log.e("XXX", cursor.getColumnName(i) + ": " + cursor.getString(i));
}
}
CALENDAR_URI = content://com.android.calendar/calendars (since Froyo) or content://calendar/ (before Froyo)
2) https://stackoverflow.com/a/11652415/411951

Samsung sms in call log, how can I delete it?

With the new Android 2.2+ operating systems deployed on Samsung phones, the call log has been replaced with a special super log. The super log contains also the information about sent sms. How I can delete this type of log? Can I use a particular Uri (content://...) to delete it? I read that Samsung uses the LogsProvider.apk to manage logs, is there the open source code of it?
Thanks.
Denis.
You can try to delete the calls using this:
context.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,
null, null);
I don't think **LogsProvider** app Samsung is open source.
Uri to be used for deleting Samsung log is "content://logs/historys".
Use this Uri to delete all the sms log of a particular number.
String smsLogUri = "content://logs/historys";
Context.getContentResolver().delete(Uri.parse(smsLogUri), " logtype = 300 and number like ?", new String[]{phoneNumber});
logtype= 300 is used to delete only sms log.
If you want to delete sms log of all numbers then use:
Context.getContentResolver().delete(Uri.parse(smsLogUri), " logtype = 300 ", null);

Checking if a new SMS has been read

I am working on a simple app for the HTC EVO that blinks the alternate notification LED when a new text message is received. I have this part working great via a Broadcast Receiver but I need some way to turn the LED off when the user has read the message(s) using their default SMS app. I'm not sure if it is best to do this in the receiver or in a background service. I found this, which might be what I am looking for, but I have no idea on how to use it as I could not find any instructions or tutorials.
Alright, I have worked out the following code which I think will meet my needs.
private int getUnreadSMSCount()
{
int count = 0;
Uri smsURI = Uri.parse("content://sms");
ContentResolver contentResolver = this.getContentResolver();
Cursor cursor = contentResolver.query(smsURI, null, "read=0", null, null);
if (cursor != null)
{
try
{
count = cursor.getCount();
}
finally
{
cursor.close();
}
}
return count;
}
Unfortunately I do not believe there is a way to do this.
When your BroadcastReceiver receives the Intent it is a copy of the Intent, same with the default SMS app. So you each have copies of the message independent of eachother.
You can set your own copy of the message to read, but you will be unable to see its status in the default SMS app. Also, the default app does not send out a broadcast that the message has been read, all that data is kept locally.
The only way you would be able to implement this would be to write a full replacement of the Messaging app.
Sorry, I hope this helps, let me know if you have any other questions.

Categories

Resources