Save/Create MMS in inbox Android
I am working on an Application which needs to be able to Save/Create a new MMS in inbox or Sent folders but I cant figure out the way.
I tried the following code but it gave me exception:
ContentValues values = new ContentValues();
values.put("address", "xxxxxxxxxxx");
values.put("body", "body 3");
values.put("read", "0");
getContentResolver().insert(Uri.parse("content://mms/inbox"), values);
And the Exception is:
ERROR/Database(118): Error inserting read=0 body=body 3 msg_box=1 date=1306153444 address=xxxxxxxxxxx
ERROR/Database(118): android.database.sqlite.SQLiteException: table pdu has no column named body: , while compiling: INSERT INTO pdu(read, body, msg_box, date, address) VALUES(?, ?, ?, ?, ?);
ERROR/Database(118): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
ERROR/Database(118): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
ERROR/Database(118): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
ERROR/Database(118): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
ERROR/Database(118): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
ERROR/Database(118): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
ERROR/Database(118): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
ERROR/Database(118): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
ERROR/Database(118): at com.android.providers.telephony.MmsProvider.insert(MmsProvider.java:347)
ERROR/Database(118): at android.content.ContentProvider$Transport.inse开发者_StackOverflow中文版rt(ContentProvider.java:174)
ERROR/Database(118): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
ERROR/Database(118): at android.os.Binder.execTransact(Binder.java:288)
ERROR/Database(118): at dalvik.system.NativeStart.run(Native Method)
ERROR/MmsProvider(118): MmsProvider.insert: failed! read=0 body=body 3 msg_box=1 date=1306153444 address=xxxxxxxxxxx
UDPATE: Exception removed by removing the line: values.put("body","body 3")
But I can't see any mms in messages.
I was having the same problem. However I successfully created and restored an MMS. It's basically reverse manipulation of database. I hope you can get an MMS from the database, right? You just need to put back appropriate values in database tables. You can get information about database tables in mmssms.db. Once you understand the mmssms.db, it's very easy to insert an MMS.
The body of the MMS is stored in content://mms/part/
. See this code for how to read from it, but remember that all of this is undocumented, unsupported and likely to change without notice.
first as you create one screen which you wants to use as the mms screen. then after as you completed to make it try this under code to send that mms to other person to whom you want. here you first declare one btn_email button on your project.
btn_email = (Button)findViewById(R.id.btn_email);
then write the onclickevent on this button which will able to help to send the mms to other person.
send mms code:
btn_email.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub System.out.println("the email button is just pressed..");
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://mnt/"+mUrl));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));
}
});
here is the code which will send the mms to other person form your sdcard path. this code using the intent code is the android default email sending screen will use.
by this way you are able to send the mms to other person.
now to save the that particulate mms which you have send that other person , as you develop that screen which you have created you just capture that whole screen...and save in sd card like..
e.g:
btn_save = (Button)findViewById(R.id.btn_save);
btn_save.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("the save button is just pressed..");
saveImageToSD();
Toast.makeText(Create_Screen_Birthday.this,"Image successfully saved",Toast.LENGTH_LONG).show();
}
});
protected void saveImageToSD() { // TODO Auto-generated method stub
System.out.println("NOW you are on the saveimage to sd card method called block..");
try
{
//String fileName = "myBitmapImage2.png";
int Current_Hour,Current_Minute,Current_Second;
RelativeLayout settext_relative;
settext_relative = (RelativeLayout)findViewById(R.id.settext_relative);
final Calendar c = Calendar.getInstance();
Current_Hour = c.get(Calendar.HOUR);
Current_Minute = c.get(Calendar.MINUTE);
Current_Second = c.get(Calendar.SECOND);
System.out.println("the value of Current_Year = "+Current_Hour);
System.out.println("the value of Current_Month = "+Current_Minute);
System.out.println("the value of Current_Date = "+Current_Second);
fileName = "Birthday_Card"+"_"+Current_Hour+"_"+Current_Minute+"_"+Current_Second+".png";
String path = "/sdcard/E-card/Birthday_Cards/";
newfileName = path + fileName;
System.out.println("the value of newfilename = "+newfileName);
System.out.println("The Filename on save card on sdcard = "+fileName);
FileOutputStream outStream = null;
File file = new File(path);
file.mkdirs();
File outputFile = new File(file, fileName);
outputFile.createNewFile();
outStream = new FileOutputStream(outputFile);
BufferedOutputStream bos = new BufferedOutputStream(outStream);
RL.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap( RL.getDrawingCache());
bitmap.compress(Bitmap.CompressFormat.PNG, 100,bos);
RL.setDrawingCacheEnabled(false);
bos.flush();
bos.close();
btn_preview.setVisibility(View.VISIBLE);
btn_save.setVisibility(View.GONE);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
this above code will save that of screen which you have send then simply you just access or fetch that image from your sdcard specific path name
精彩评论