问题描述
我一直对短信应用程序。一切顺利,直到昨天,当我更新了我的Nexus 4到Android 4.4,奇巧。功能,如标记短信为已读/未读,并删除在一个线程中的所有邮件都停止工作。这究竟是为什么?它适用于其他三星设备(不运行奇巧)。
这是我的code到邮件标记为已读或未读:
公共静态无效markRead(最终上下文的背景下,最终开放的URI,
最终诠释读){
Log.d(TAG,markRead(+ URI +,+阅读+));
如果(URI == NULL){
返回;
}
的String [] SEL = Message.SELECTION_UNREAD;
如果(阅读== 0){
SEL = Message.SELECTION_READ;
}
最后ContentResolver的CR = context.getContentResolver();
最后ContentValues CV =新ContentValues();
cv.put(Message.PROJECTION [Message.INDEX_READ],读);
尝试 {
cr.update(URI,CV,Message.SELECTION_READ_UNREAD,SEL);
}赶上(抛出:IllegalArgumentException E){
Log.e(TAG,失败的更新,E);
Toast.makeText(上下文,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
有关删除线程中的所有邮件,我用的:
公共静态无效deleteMessages(最终上下文的背景下,最终开放的URI,
最终诠释称号,最终诠释消息,最后活动活动){
Log.i(TAG,deleteMessages(..,+ URI +,...));
最终生成器生成器=新生成器(背景);
builder.setTitle(职称);
builder.setMessage(消息);
builder.setNegativeButton(android.R.string.no,NULL);
builder.setPositiveButton(android.R.string.yes,
新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(最终DialogInterface对话框,
最终诠释它){
最终诠释RET = context.getContentResolver()。删除(
URI,NULL,NULL);
Log.d(TAG,删除+ RET);
如果(活性=空&安培;!&安培;!activity.isFinishing()){
activity.finish();
}
如果(保留大于0){
Conversation.flushCache();
Message.flushCache();
SmsReceiver.updateNewMessageNotification(背景下,
空值);
// adapter.notifyDataSetChanged();
}
尝试 {
testFromFragment(上下文);
}赶上(例外五){
e.printStackTrace();
}
}
});
builder.show();
}
随着Android 4.4系统,有几个事情是关于短信改变。其中之一是,只有注册为默认的短信应用程序应用程序有写访问提供商的事实。
检查这里上更改SMS短的导语。
<一个href="http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html?m=1"相对=nofollow>检查此链接在深入研究更。这其中解释了标准你的应用需要满足成为默认的消息应用程序。
而这里的官方有趣的东西。
因此,如果您的应用程序是不是默认的消息应用程序,这将是为什么指定的功能已停止工作。
一个可能的解决方法默认提供的限制可以在这里回答。
I have been working on an SMS application. Everything was smooth until yesterday, when I updated my Nexus 4 to Android 4.4, KitKat. Features such as marking an SMS as read/unread, and deleting all messages in a thread have stopped working. Why is this happening? It works on other Samsung devices (not running KitKat).
This is my code to mark a message as read or unread:
public static void markRead(final Context context, final Uri uri,
final int read) {
Log.d(TAG, "markRead(" + uri + "," + read + ")");
if (uri == null) {
return;
}
String[] sel = Message.SELECTION_UNREAD;
if (read == 0) {
sel = Message.SELECTION_READ;
}
final ContentResolver cr = context.getContentResolver();
final ContentValues cv = new ContentValues();
cv.put(Message.PROJECTION[Message.INDEX_READ], read);
try {
cr.update(uri, cv, Message.SELECTION_READ_UNREAD, sel);
} catch (IllegalArgumentException e) {
Log.e(TAG, "failed update", e);
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
For deleting all messages in a thread, I use:
public static void deleteMessages(final Context context, final Uri uri,
final int title, final int message, final Activity activity) {
Log.i(TAG, "deleteMessages(..," + uri + " ,..)");
final Builder builder = new Builder(context);
builder.setTitle(title);
builder.setMessage(message);
builder.setNegativeButton(android.R.string.no, null);
builder.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog,
final int which) {
final int ret = context.getContentResolver().delete(
uri, null, null);
Log.d(TAG, "deleted: " + ret);
if (activity != null && !activity.isFinishing()) {
activity.finish();
}
if (ret > 0) {
Conversation.flushCache();
Message.flushCache();
SmsReceiver.updateNewMessageNotification(context,
null);
// adapter.notifyDataSetChanged();
}
try {
testFromFragment(context);
} catch (Exception e) {
e.printStackTrace();
}
}
});
builder.show();
}
With Android 4.4, several things have changed with regard to SMS. Among them is the fact that only the app that is registered as the default SMS app has write access to the provider.
Check here for a short blurb on changes to SMS.
Check this link for a more in depth look. This one explains what criteria your app needs to meet to be the default messaging app.
And here's the official fun stuff.
So, if your app is not the default messaging app, that would be why the specified functionalities have stopped working.
A possible workaround for the default Provider restriction can be found in the answer here.
这篇关于标记短信为已读/未读或已删除的邮件无法正常工作的奇巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!