开发者

Android SMS API

开发者 https://www.devze.com 2022-12-12 07:08 出处:网络
I know that the SMS content provider is not part of the public API (at least not documented), but if I understand correctly it\'s still possible to use many of the SMS features as long as you know how

I know that the SMS content provider is not part of the public API (at least not documented), but if I understand correctly it's still possible to use many of the SMS features as long as you know how to use the API(?).

E.g it's pretty straightforward to insert an SMS into your inbox:

 ContentValues values = new ContentValues();
 values.put("address", "+457014921911"); 
 contentResolver.insert(Uri.parse("content://sms"), values);

Unfortunately this does not trigger the standard "new-SMS-in-your-inbox" notification. Is it possible to trigger this manually?

Edit: AFAIK the "standard mail application (Messaging)" in Android is listening for incoming S开发者_JAVA百科MSes using the android.permission.RECEIVE_SMS permission. And then, when a new SMS has arrived, a status bar notification is inserted with a "special" notification id. So one solution to my problem (stated above) could be to find, and send the correct broadcast intent; something like "NEW SMS HAS ARRIVED"-intent.

Edit: Downloaded a third party messaging application (chompsms) from Android market. This application satisfies my needs better. When i execute the code above the chompsms notice the new sms and shows the "standard status bar notification". So I would say that the standard Android Messaging application is not detecting sms properly? Or am I wrong?


Unfortunately the code responsible for these notifications is hidden in the messaging application. The class MessagingNotification has a static method updateAllNotifications that you could call using a PathClassLoader and reflection:

PathClassLoader c = new PathClassLoader("/system/app/Mms.apk", getClassLoader());
Class.forName("com.android.mms.util.ContactInfoCache", true, c)
    .getMethod("init", Context.class).invoke(null, context);
Class.forName("com.android.mms.transaction.MessagingNotification", true, c)
    .getMethod("updateAllNotifications", Context.class).invoke(null, context);

This is obviously a very bad idea for several reasons but I can't think of another way to do what you described.


Could you trigger a PUSH notification after the SMS?

Thread: Does Android support near real time push notification?


Maybe you should replace

content://sms

with

content://sms/inbox
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号