短信无法在Kitkat 4.4上保存<已设置为默认消息传递应用程序> [英] Sms doesn't save on Kitkat 4.4 <Already set as default messaging app>
问题描述
即使我已将短信设置为默认消息传递,我的短信应用程序也不会将短信保存到设备.我需要支持android pre-kitkat,所以我做了一些研究,并选择了2个BroadcastReceiver,它们具有相同的内容,但名称不同. onReceive()方法工作正常,但是一旦我退出应用程序并输入它,短信就会消失.我检查了股票消息,但也没有短信.我不知道是什么问题
My Sms app does not save the sms to the device even though I already set it as the default messaging. I need to support android pre-kitkat so I did a bit researching and had 2 BroadcastReceiver that have the same content but different name. The onReceive() method is working fine, but as soon as I quit the app and enter it the sms disappears. I checked in the stock messaging but there's no sms either. I cant figure out what the issue is
我的Android清单:
My Androidmanifest:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SmsActivity"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow" >
<meta-data
android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".NewSmsBroadcastReceiver"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<receiver android:name=".SmsBroadcastReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver
android:name=".MmsReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH" >
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<activity android:name=".SendActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<service
android:name=".HeadlessSmsSendService"
android:exported="true"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" >
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
<activity
android:name=".SendActivity"
android:label="@string/app_name"
android:parentActivityName=".SmsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.wyrmise.melriss.SmsActivity" />
</activity>
<activity
android:name=".ThreadActivity"
android:label="@string/title_activity_thread" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.wyrmise.melriss.SmsActivity" />
</activity>
</application>
</manifest>
BroadcastReceiver
BroadcastReceiver
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String address = "";
String smsBody = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage
.createFromPdu((byte[]) sms[i]);
smsBody = smsMessage.getMessageBody().toString();
address = smsMessage.getOriginatingAddress();
}
Message msg = new Message();
msg.messageNumber=address;
msg.messageContent=smsBody;
SimpleDateFormat hours = new SimpleDateFormat("h:mm a",
Locale.US);
msg.messageDate=hours.format(new Date());
SmsActivity inst = SmsActivity.instance();
inst.pushNotification(msg);
inst.updateList(msg);
}
}
}
推荐答案
默认的SMS应用负责将所有传入消息写入提供程序.即使您已为应用程序实现了接收器,以从SMS_RECEIVED
广播中读取消息,您仍需要实际将消息写入提供者.例如:
The default SMS app is responsible for writing all incoming messages to the Provider. Even though you've implemented a Receiver for your app to read the message from the SMS_RECEIVED
broadcast, you still need to actually write the message to the Provider. For example:
ContentValues values = new ContentValues();
values.put(Sms.ADDRESS, address);
values.put(Sms.BODY, smsBody);
context.getContentResolver().insert(Sms.CONTENT_URI, values);
这篇关于短信无法在Kitkat 4.4上保存<已设置为默认消息传递应用程序>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!