在Android 4.4.2上以编程方式插入SMS [英] Insert SMS programmatically on Android 4.4.2

查看:112
本文介绍了在Android 4.4.2上以编程方式插入SMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码在旧版本的Android上可以正常使用,但在4.4.2上不能正常工作.没有错误发生,logcat中也没有任何内容,但是消息没有显示在模拟器的默认SMS应用程序中.所以我的问题是为什么它在4.4.2上不起作用,我需要做些什么才能使其再次起作用.

I have the following code which works fine in older versions of Android, but not on 4.4.2. No errors occur and nothing in logcat, but the messages do not show up in the default SMS app in the emulator. So my question is why it doesn't work on 4.4.2 and what I have to do to make it work again.

private void addSMS()
{       
    Uri uri = Uri.parse("content://sms/");
    ContentValues cv2 = new ContentValues();
    cv2.put("address", "+91956322222");
    cv2.put("date", "1309632433677");
    cv2.put("read", 1);
    cv2.put("type", 2);
    cv2.put("body", "Hey");
    getContentResolver().insert(uri, cv2);
    /** This is very important line to solve the problem */
    getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null);
    cv2.clear();
  }

推荐答案

从Android 4.4 Kitkat开始,如果没有默认的短信应用,则无法执行任何类型的短信相关操作.还原和备份应用程序也无法执行此操作.他们中的大多数人已经更新了他们的应用程序以支持此功能,现在要求用户将它们选择为默认的SMS应用程序.

Starting from Android 4.4 Kitkat, it is not possible to perform any kind of SMS related operations without being the default SMS app. Restore and Backup apps cannot do it either. Most of them have updated their app to support this functionality and now ask the user to select them as the default SMS app.

这篇关于在Android 4.4.2上以编程方式插入SMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆