My questions specific only for Android 6 (starting from v23 of SDK). I need to get all SMS, even draft for future processing. Nothing special here, used the following peace of code:
context.getContentResolver().query(Uri.parse("content://sms/"),
new String[] {...}, null, null, null)
And this work perfect for Android 5, meaning that I get all SMS messages including draft. But at all devices with Android 6, I get only sent and received messages and NO DRAFT. Try to make my app default SMS before trying to query SMS – but no luck, at Android 6 i still cannot get draft messages. What the problem?
I've already found some related posts
SMS missing from content provider results on Android Marshmallow
But this do not solve my issue at all.
For Marshmallow you need to add run time permissions to read messages .
Check permission like this
int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_SMS);
If permission denied tha ask at run time like that
ActivityCompat.requestPermissions(this, new String[]{{Manifest.permission.READ_SMS}, PERMISSIONS_REQUEST_READMESSAGE);
to access draft this is URI for content provider.
Content provider for draft is
content://sms/draft
Note: dont forget to add permissions
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
I believe what your looking for is found in this answer. It provides a list of URI's for accessing the different SMS boxes. The one specifically for the draft SMS messages is
content://sms/draft
Query on URI content://sms/draft will return only the draft messages that are stored in SMS provider.
Default android messaging application implementation stores the draft messages within the application and will not add the drafts to SMS provider.
Only the draft messages that are part of SMS provider (can added using SMSManager's hidden API addTextMessageDraft) will be returned as results when query on URI content://sms/draft is performed.
Related
I try to develop anti-smishing solution, which listen in background and analyze new SMS.
If I'm not default SMS app, I can only read the SMS.
I found information about some exceptions in use of SMS permission group for Anti-Phishing, where I have access not only to read, but also to write.
How does it work? For now I'm not able to write or edit any SMS in Android Studio. When Google accepts my request/form I will have some extra code for exception or something like it?
https://support.google.com/googleplay/android-developer/answer/10208820?hl=en&ref_topic=2364761#zippy=%2Cwyj%C4%85tki
Today i received this mail from google team my app publishing status: Rejected.
Unable to trigger default handler prompt prior to runtime permissions
*If your app is a default handler, the default handler prompt must precede the runtime permission prompt.
Based on our review, your app doesn’t appear to properly trigger the default handler prompt prior to the runtime permissions prompt. Please add the default handler prompt prior to any runtime permissions prompt.*
Please help for solve this and i also used default handler prompt but don't know why google sent me this mail.
You need to explicitly prompt the default handler instead of simply declaring permissions in the manifest.
RoleManager roleManager = (RoleManager)
activity.getSystemService(Context.ROLE_SERVICE);
Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
activity.startActivityForResult(intent, requestCode);
For changing the default handler:
Intent setDefaultSmsIntent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
setDefaultSmsIntent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
startActivityForResult(setDefaultSmsIntent, requestCode);
From Google's Android documentation, this about the Play Store policy.
Given the sensitive user information that an app accesses while
serving as a default handler, your app cannot become a default handler
unless it meets the following Play Store listing and core
functionality requirements:
Your app must be able to perform the functionality for which it's a
default handler. For example, a default SMS handler should be able to
send text messages.
Your app must provide a privacy policy.
Your app must make its core functionality clear in the Play Store
description.
For example, a default Phone handler should describe its phone-related
capabilities in the description.
Your app must declare permissions that are appropriate for its use
case. For more details about which permissions you can declare as a
given handler, see the guidance on using SMS or call log permission
groups in the Play Console Help Center.
Your app must ask to become a default handler before it requests the
permissions associated with being that handler. For example, an app
must request to become the default SMS handler before it requests the
READ_SMS permission.
I have four questions regarding Android default email program. Please help me to answer the questions respectively.
Thanks in Advance
1) How can we access the Device Database?
2) How can we setup email on Emulator?
3) Can we read Email Content Through Email Content Provider like (AttachementProvider.java)
I have found in Git
4) Can anyone tell me the correct Email URI
I have found the URI that is not working
"content://com.android.email.attachmentprovider"
1) How can we access the Device Database ?
You can't.
2) How can we setup email on Emulator ?
I would assume that you tap on the icon in the launcher and follow the prompts, the way you would set it up on a regular phone. Bear in mind that this application may not exist on all phones.
3) Can we read Email Content Through Email Content Provider like ( AttachementProvider.java) i have found in Git
There is no documented and supported API for any email client in the Android SDK.
4) can any one tell me the corret Email URI i have found the URI that is not working "content://com.android.email.attachmentprovider"
I repeat, there is no documented and supported API for any email client in the Android SDK. You have been specifically told not to use undocumented content providers, since they will be changed without warning and, again, may not exist on all devices.
Since there is the permission called
android.permission.READ_OWNER_DATA
there MUST be a way to read the phone owner info on an android device.
The only thing I could find on the net is this:
Uri uri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, "owner");
Cursor c = managedQuery(uri, null, null, null, null);
But 1) that doesn't work (owner path unknown) and 2) Contacts.People is deprecated (I guess this should now be ContactsContract.Contacts.CONTENT_URI)
I can't even get the mobile phone number of the device using the TelephonyManager (getLine1Number) ... even the built-in phoneinfo screen shows "unknown" for the phonenumber.
Anyway, seems like I can't figure it out on my own and can't find anything useful on the web either (except for the outdated (?) code above). Although I believe the above approach must be the right one (using some content provider that provides the owner info). There simply is no documentation about this except that Android provides the permission setting "android.permission.READ_OWNER_DATA" but no info about how to actually do that kind of thing.
Does anybody know how to get to the phone owner info (name, address, email, phone, ...) on Android? Thanks a mill!
(Background: Developing on Android SDK 2.1, Testing on Emulator and HTC Desire)
Android is open source. It seems, based on searching for READ_OWNER_DATA, that the "/people/owner" path in the contacts provider returns a cursor with some sort of owner information — assuming that information has been entered already by the user.
You'd have to double check the AOSP to see if that still applies for the newer contacts API.
this permission was removed
see :
http://developer.android.com/sdk/api_diff/9/changes/android.Manifest.permission.html
I'm working on an SMS Application for Android, which undoubtedly needs to send SMSes (go figure! ;)
Now, i know there are a plenty of sources on the net that describe using the SmsManager to send SMSes...But, apparently, when using that method, the SMSes aren't stored in the "SENT" Folder...which is kind of a basic requirement for an SMS application.
How do i add an entry (of a message) into the "Outbox", so that it gets sent (and stored in the SENT Folder Automatically)....
What would be the Values of the fields "_id,threadid,read,status,type,service_center" (Attributes of the message table)??
Any other alternatives are also welcome. :)
Thanks in Advance...
I had been looking for a work around this issue. Add the following lines of code after sending the sms... this will make an entry in the outbox of native sms application
ContentValues values = new ContentValues();
values.put("address", number);
values.put("body", desc);
getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/sent"), values);
i would like to get help from ppl who could tell how to use this content provider to make entry for multiple receivers... Thanks..
But, apparently, when using that
method, the SMSes aren't stored in the
"SENT" Folder...which is kind of a
basic requirement for an SMS
application.
The concept of a "SENT" folder is a feature of an application, not the operating system. If you wish to create your own SMS client application, create your own "SENT" folder as a feature of that application. You know what messages you are sending, so you can store them wherever you like (e.g., SQLite database).
If you want to send SMS messages and have them appear in the "SENT" folder of the user's chosen SMS client, don't use SmsManager. Instead, use ACTION_SENDTO and have the message be sent by the user's chosen SMS client, as is demonstrated by this sample project.
At least on 6.0 and 7.0 the system app com.android.phone is responsible for storing the messages sent by other apps. Unfortunately, this functionality is broken by some manufacturers and this is why we don't see sent messages.
It does work on AVD though. See the method persistSentMessageIfRequired() in com.android.internal.telephony.SMSDispatcher.
Only this app or the selected default SMS app has a write permission to the SMS content provider. When you send it using the SMS app, it calls insert() directly. When you use SmsManager in your app, the system app com.android.phone somehow gets notified, performs the sending and then stores the sent message. Here's the callstack (I didn't dig further):
at android.os.Handler.obtainMessage(Handler.java:293)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSmsByPstn(GsmSMSDispatcher.java:291)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSms(GsmSMSDispatcher.java:274)
at com.android.internal.telephony.SMSDispatcher.sendRawPdu(SMSDispatcher.java:999)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendText(GsmSMSDispatcher.java:198)
at com.android.internal.telephony.ImsSMSDispatcher.sendText(ImsSMSDispatcher.java:206)
at com.android.internal.telephony.IccSmsInterfaceManager.sendTextInternal(IccSmsInterfaceManager.java:452)
at com.android.internal.telephony.IccSmsInterfaceManager.sendText(IccSmsInterfaceManager.java:393)
at com.android.internal.telephony.UiccSmsController.sendTextForSubscriber(UiccSmsController.java:136)
at com.android.internal.telephony.ISms$Stub.onTransact(ISms.java:201)
at android.os.Binder.execTransact(Binder.java:565)
After the SMS is sent, the app posts a Handler message to itself:
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
at com.android.providers.telephony.SmsProvider.insertInner(SmsProvider.java:618)
at com.android.providers.telephony.SmsProvider.insert(SmsProvider.java:442)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:264)
at android.content.ContentResolver.insert(ContentResolver.java:1274)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistSentMessageIfRequired(SMSDispatcher.java:1445)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistOrUpdateMessage(SMSDispatcher.java:1476)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.onSent(SMSDispatcher.java:1537)
at com.android.internal.telephony.SMSDispatcher.handleSendComplete(SMSDispatcher.java:638)
at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:274)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.handleMessage(GsmSMSDispatcher.java:108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)