我正在尝试构建自己的消息收发应用程序,并且正在尝试设置彩信。我想通过MMS发送一些额外的信息(例如groupName和其他一些元数据)。我能够使用Android SmsManager.sendMultimediaMessage()
和SmsManager.downloadMultimediaMessage()
功能成功发送MMS消息。从文档看来,我应该可以使用configOverrides
发送更多信息。但是,当我尝试下载彩信时,configOverrides始终为空...
发送彩信的代码:
Bundle configOverrides = new Bundle();
configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, true);
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(getContext(), subscriptionId);
if (mmsConfig != null) {
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
String tempHttpParams = overridden.getHttpParams();
if(tempHttpParams == null || tempHttpParams.equals("")) {
tempHttpParams = "groupName=test";
} else {
tempHttpParams += "|groupName=test";
}
Log.d(TAG, "httpParams: " + tempHttpParams);
configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, tempHttpParams);
configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, overridden.getMaxMessageSize());
Log.d(TAG, "configOverride: " + configOverrides.toString());
}
smsManager.sendMultimediaMessage(getContext(),
pointer.getUri(),
null,
configOverrides,
getPendingIntent());
下载彩信的代码:
Bundle configOverrides = new Bundle();
smsManager.downloadMultimediaMessage(getContext(),
contentLocation,
pointer.getUri(),
configOverrides,
getPendingIntent());
waitForResult();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Util.copy(pointer.getInputStream(), baos);
pointer.close();
Log.i(TAG, baos.size() + "-byte response: ");// + Hex.dump(baos.toByteArray()));
RetrieveConf retrieved = (RetrieveConf) new PduParser(baos.toByteArray()).parse();
Log.d(TAG, "configOverrides: " + configOverrides.toString());
Log.d(TAG, "httpParams: " + configOverrides.getString(SmsManager.MMS_CONFIG_HTTP_PARAMS));
Log.d(TAG, "smsManager.getCarrierConfigValues(): " + smsManager.getCarrierConfigValues().toString());
记录详细信息:
D/OutgoingLollipopMmsConnection: httpParams: groupName=test
D/OutgoingLollipopMmsConnection: configOverride: Bundle[{httpParams=groupName=test, enableGroupMms=true, maxMessageSize=1048576}]
I/IncomingLollipopMmsConnection: 350101-byte response:
D/IncomingLollipopMmsConnection: configOverrides: Bundle[{}]
D/IncomingLollipopMmsConnection: httpParams: null
D/IncomingLollipopMmsConnection: smsManager.getCarrierConfigValues(): Bundle[mParcelledData.dataSize=1648]
我环顾四周,使用configOverrides找不到用户的任何示例。我是否缺少有关如何下载它们的步骤?还是有更好的方法通过MMS发送额外的元数据? (我知道在Lollipop开发人员必须构建自己的MMS api之前,它们基本上只是HTTP Post消息,但我认为使用Android API会很好。)