我正在为KitKat中的默认短信应用编写替代品。我读过很多东西 喜欢:Getting Your SMS Apps Ready for KitKat
我有以下代码:
public void saveMessage(Context context, String addr, String text){
ContentValues values = new ContentValues();
values.put(Telephony.Sms.ADDRESS, addr );
values.put(Telephony.Sms.DATE, 0);
values.put(Telephony.Sms.DATE_SENT, 0);
values.put(Telephony.Sms.BODY, text);
values.put(Telephony.Sms.READ, 0 );
values.put(Telephony.Sms.STATUS, 0 );
values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX);
values.put(Telephony.Sms.SEEN, 0;
values.put(Telephony.Sms.THREAD_ID, 0);
values.put(Telephony.Sms.CREATOR, "");
values.put(Telephony.Sms.ERROR_CODE, 0);
values.put(Telephony.Sms.LOCKED, 0);
values.put(Telephony.Sms.PERSON, 0);
values.put(Telephony.Sms.SUBJECT, "");
Uri mMessageUri = Telephony.Sms.Inbox.CONTENT_URI;
Uri result = context.getContentResolver().insert(mMessageUri, values);
}
显示如下:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.provider.Telephony.SMS_RECEIVED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MessageListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ConversationActivity"
android:label="@string/title_activity_conversation" >
<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>
<receiver android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<!-- BroadcastReceiver that listens for incoming MMS messages -->
<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>
<service android:name=".HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true" >
<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>
</application>
如您所见,我可以选择此应用作为系统中的默认短信应用。 当我收到消息并调用 saveMessage 函数时,它什么也没写。 既不是内容://短信,不是内容://短信/收件箱,也不是内容://短信/发送。
我在这里缺少什么?我需要更多权限来定义吗?