本文介绍了获取附件从未读彩信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得附件从读彩信,但codeS我也不允许我这样做。我该如何去这样做?
codeS从这里:
私人无效checkMMSMessages(){
//创建字符串数组存储查询以后
的String []列= NULL;
的String []值= NULL;
//调用ContentResolver的查询与URI列的内容:彩信
光标curPdu = getContentResolver()查询(Uri.parse(内容:// MMS),NULL,NULL,NULL,NULL);
如果(curPdu.moveToNext()){
//读取字符串= curRead.getString(curRead.getColumnIndex(读));
//获取消息的ID
字符串ID = curPdu.getString(curPdu.getColumnIndex(_ ID));
//获取消息的线程ID
字符串的thread_id = curPdu.getString(curPdu.getColumnIndex(thread_id单));
//获取受消息(如果有的话)
字符串主题= curPdu.getString(curPdu.getColumnIndex(分));
//获取消息的日期
字符串日期= curPdu.getString(curPdu.getColumnIndex(日));
字符串selectionAddr =新的String(MSG_ID ='+编号+');
乌里uriAddr = Uri.parse(内容:// MMS /+编号+/地址);
光标curAddr = getContentResolver()查询(uriAddr,NULL,NULL,NULL,NULL);
如果(curAddr.moveToNext()){
串CONTACT_ID = curAddr.getString(curAddr.getColumnIndex(CONTACT_ID));
字符串的地址= curAddr.getString(curAddr.getColumnIndex(地址));
字符串selectionPart =新的String(中期='+编号+');
光标curPart = getContentResolver().query(Uri.parse(内容:// MMS /部分),NULL,NULL,NULL,NULL);
//光标curPart = context.getContentResolver().query(Uri.parse(内容:// MMS /+编号+/一部分),NULL,NULL,NULL,NULL);
而(curPart.moveToNext())
{
列= curPart.getColumnNames();
如果(价值== NULL)
值=新的String [columns.length]
的for(int i = 0; I< curPart.getColumnCount();我++){
值[I] = curPart.getString(ⅰ);
}
串contact_idd = curPart.getString(0);
如果(值[3] .equals(为image / jpeg)||值[3] .equals(图像/ BMP)||
值[3] .equals(图像/ GIF)||值[3] .equals(图像/ JPG)||
值[3] .equals(图像/ PNG))
{
GetMmsAttachment(值[0],值[12]);
//Toast.makeText(getApplicationContext(),检索到的彩信附件,Toast.LENGTH_LONG);
}
}
}
}
}
私人无效GetMmsAttachment(字符串_id,字符串_data)
{
乌里partURI = Uri.parse(内容:// MMS /零件/+ _id);
字符串文件路径=/sdcard/photo.jpg;
InputStream的是= NULL;
OutputStream的picFile = NULL;
点阵位图= NULL;
尝试 {
,是= getContentResolver()openInputStream(partURI);
位= BitmapFactory.de codeStream(是);
picFile =新的FileOutputStream(文件路径);
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,picFile);
picFile.flush();
picFile.close();
}
赶上(例外五)
{
e.printStackTrace();
//抛出新MmsException(E);
}
}
解决方案
想通了自己,在codeS如下:
私人无效checkMMSMessages(){
的String []列= NULL;
的String []值= NULL;
字符串读=读= 0;
光标curPdu = getContentResolver()查询(Uri.parse(内容:// MMS),空,阅读,NULL,NULL);。
如果(curPdu.moveToNext()){
字符串ID = curPdu.getString(curPdu.getColumnIndex(_ ID));
光标curPart = getContentResolver()查询。(Uri.parse(内容:// MMS /+编号+/一部分),NULL,NULL,NULL,NULL);
而(curPart.moveToNext())
{
列= curPart.getColumnNames();
如果(价值== NULL)
值=新的String [columns.length]
的for(int i = 0; I< curPart.getColumnCount();我++){
值[I] = curPart.getString(ⅰ);
}
如果(值[3] .equals(为image / jpeg)||值[3] .equals(图像/ BMP)||
值[3] .equals(图像/ GIF)||值[3] .equals(图像/ JPG)||
值[3] .equals(图像/ PNG))
{
GetMmsAttachment(值[0],值[12]);
}
}
}
}
私人无效GetMmsAttachment(字符串_id,字符串_data)
{
乌里partURI = Uri.parse(内容:// MMS /零件/+ _id);
字符串文件路径=/sdcard/photo.jpg;
InputStream的是= NULL;
OutputStream的picFile = NULL;
点阵位图= NULL;
尝试 {
,是= getContentResolver()openInputStream(partURI);
位= BitmapFactory.de codeStream(是);
picFile =新的FileOutputStream(文件路径);
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,50,picFile);
picFile.flush();
picFile.close();
}
赶上(例外五)
{
e.printStackTrace();
//抛出新MmsException(E);
}
}
I would like to get attachment from unread MMS messages, but the codes I have doesn't allow me to do so. How do I go about doing that?
Codes modified from here:
private void checkMMSMessages(){
// Create string arrays to store the queries later on
String[] columns = null;
String[] values = null;
// Calls the ContentResolver to query for columns with URI "content:mms"
Cursor curPdu = getContentResolver().query(Uri.parse("content://mms"), null, null, null, null);
if(curPdu.moveToNext()){
//String read = curRead.getString(curRead.getColumnIndex("read"));
// Gets ID of message
String id = curPdu.getString(curPdu.getColumnIndex("_id"));
// Gets thread ID of message
String thread_id = curPdu.getString(curPdu.getColumnIndex("thread_id"));
// Gets subject of message (if any)
String subject = curPdu.getString(curPdu.getColumnIndex("sub"));
// Gets date of message
String date = curPdu.getString(curPdu.getColumnIndex("date"));
String selectionAddr = new String ("msg_id = '" + id + "'");
Uri uriAddr = Uri.parse ("content://mms/" + id + "/addr");
Cursor curAddr = getContentResolver().query(uriAddr, null, null, null, null);
if(curAddr.moveToNext()){
String contact_id = curAddr.getString (curAddr.getColumnIndex ("contact_id"));
String address = curAddr.getString (curAddr.getColumnIndex ("address"));
String selectionPart = new String ("mid = '" + id + "'");
Cursor curPart = getContentResolver ().query(Uri.parse ("content://mms/part"), null, null, null, null);
//Cursor curPart = context.getContentResolver ().query(Uri.parse ("content://mms/" + id + "/part"), null, null, null, null);
while(curPart.moveToNext())
{
columns = curPart.getColumnNames();
if(values == null)
values = new String[columns.length];
for(int i=0; i< curPart.getColumnCount(); i++){
values[i] = curPart.getString(i);
}
String contact_idd = curPart.getString(0);
if(values[3].equals("image/jpeg") || values[3].equals("image/bmp") ||
values[3].equals("image/gif") || values[3].equals("image/jpg") ||
values[3].equals("image/png"))
{
GetMmsAttachment(values[0],values[12]);
//Toast.makeText(getApplicationContext(), "Retrieved MMS attachment", Toast.LENGTH_LONG);
}
}
}
}
}
private void GetMmsAttachment(String _id, String _data)
{
Uri partURI = Uri.parse("content://mms/part/" + _id );
String filePath = "/sdcard/photo.jpg";
InputStream is = null;
OutputStream picFile = null;
Bitmap bitmap = null;
try {
is = getContentResolver().openInputStream(partURI);
bitmap = BitmapFactory.decodeStream(is);
picFile = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, picFile);
picFile.flush();
picFile.close();
}
catch (Exception e)
{
e.printStackTrace();
//throw new MmsException(e);
}
}
解决方案
Figured out myself, the codes are as follows:
private void checkMMSMessages() {
String[] columns = null;
String[] values = null;
String read = "read = 0";
Cursor curPdu = getContentResolver().query(Uri.parse("content://mms"), null, read, null, null);
if(curPdu.moveToNext()){
String id = curPdu.getString(curPdu.getColumnIndex("_id"));
Cursor curPart = getContentResolver().query(Uri.parse ("content://mms/" + id + "/part"), null, null, null, null);
while(curPart.moveToNext())
{
columns = curPart.getColumnNames();
if(values == null)
values = new String[columns.length];
for(int i=0; i< curPart.getColumnCount(); i++){
values[i] = curPart.getString(i);
}
if(values[3].equals("image/jpeg") || values[3].equals("image/bmp") ||
values[3].equals("image/gif") || values[3].equals("image/jpg") ||
values[3].equals("image/png"))
{
GetMmsAttachment(values[0],values[12]);
}
}
}
}
private void GetMmsAttachment(String _id, String _data)
{
Uri partURI = Uri.parse("content://mms/part/" + _id );
String filePath = "/sdcard/photo.jpg";
InputStream is = null;
OutputStream picFile = null;
Bitmap bitmap = null;
try {
is = getContentResolver().openInputStream(partURI);
bitmap = BitmapFactory.decodeStream(is);
picFile = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, picFile);
picFile.flush();
picFile.close();
}
catch (Exception e)
{
e.printStackTrace();
//throw new MmsException(e);
}
}
这篇关于获取附件从未读彩信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!