-1
我正在尝试制作自己的消息传递应用程序。我能够发送短信和彩信我能够将传入的短信写入android数据库。我制作了我的应用默认消息应用。但是如何用图像和文本将收到的彩信显示到我的收件箱中。我正在使用https://github.com/klinker41/android-smsmms作为库。如何接收传入的MMS并写入Android数据库
我正在尝试制作自己的消息传递应用程序。我能够发送短信和彩信我能够将传入的短信写入android数据库。我制作了我的应用默认消息应用。但是如何用图像和文本将收到的彩信显示到我的收件箱中。我正在使用https://github.com/klinker41/android-smsmms作为库。如何接收传入的MMS并写入Android数据库
您应该使用该库的MmsReceivedReceiver
类。看看它的执行情况:
public class MmsReceivedReceiver extends BroadcastReceiver {
private static final String TAG = "MmsReceivedReceiver";
public static final String MMS_RECEIVED = "com.klinker.android.messaging.MMS_RECEIVED";
public static final String EXTRA_FILE_PATH = "file_path";
public static final String EXTRA_LOCATION_URL = "location_url";
private static final String LOCATION_SELECTION =
Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?";
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "MMS has finished downloading, persisting it to the database");
String path = intent.getStringExtra(EXTRA_FILE_PATH);
Log.v(TAG, path);
FileInputStream reader = null;
try {
File mDownloadFile = new File(path);
final int nBytes = (int) mDownloadFile.length();
reader = new FileInputStream(mDownloadFile);
final byte[] response = new byte[nBytes];
reader.read(response, 0, nBytes);
DownloadRequest.persist(context, response,
new MmsConfig.Overridden(new MmsConfig(context), null),
intent.getStringExtra(EXTRA_LOCATION_URL),
Utils.getDefaultSubscriptionId(), null);
Log.v(TAG, "response saved successfully");
Log.v(TAG, "response length: " + response.length);
mDownloadFile.delete();
} catch (FileNotFoundException e) {
Log.e(TAG, "MMS received, file not found exception", e);
} catch (IOException e) {
Log.e(TAG, "MMS received, io exception", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
Log.e(TAG, "MMS received, io exception", e);
}
}
}
handleHttpError(context, intent);
DownloadManager.finishDownload(intent.getStringExtra(EXTRA_LOCATION_URL));
}
private void handleHttpError(Context context, Intent intent) {
final int httpError = intent.getIntExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, 0);
if (httpError == 404 ||
httpError == 400) {
// Delete the corresponding NotificationInd
SqliteWrapper.delete(context,
context.getContentResolver(),
Telephony.Mms.CONTENT_URI,
LOCATION_SELECTION,
new String[]{
Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
intent.getStringExtra(EXTRA_LOCATION_URL)
});
}
}
}
从库的例子实现类似SmsReceiver
。