在收件箱Android中保存/创建彩信

时间:2011-05-23 12:40:02

标签: android mms

我正在开发一个应用程序,它需要能够在收件箱或已发送文件夹中保存/创建新的彩信,但我无法找到方法。

我尝试了以下代码,但它给了我例外:

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);

而且例外是:

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.insert(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:删除行删除了异常:values.put("body","body 3")但我在消息中看不到任何mms。

3 个答案:

答案 0 :(得分:5)

我遇到了同样的问题。但是我成功创建并恢复了MMS。它基本上是对数据库的反向操作。我希望你能从数据库中获取彩信,对吗?您只需要在数据库表中放回适当的值。您可以在mmssms.db中获取有关数据库表的信息。一旦理解了mmssms.db,就可以很容易地插入MMS。

答案 1 :(得分:2)

MMS的正文存储在content://mms/part/中。请参阅this code了解如何阅读,但请记住,所有这些都没有记录,不受支持,可能会更改,恕不另行通知。

答案 2 :(得分:-6)

首先创建一个您想用作mms屏幕的屏幕。 然后,当你完成后,在代码下尝试这个,将mms发送给你想要的其他人。 在这里,您首先在项目中声明一个btn_email按钮。

btn_email =(按钮)findViewById(R.id.btn_email);

然后在此按钮上写下onclickevent,这将有助于将mms发送给其他人。

发送mms代码:

btn_email.setOnClickListener(new View.OnClickListener()                 {                     @覆盖                     public void onClick(查看v){                         // TODO自动生成的方法存根                         System.out.println(“只按了电子邮件按钮..”);

                    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:"));
                }

            });

这里是代码,它将mms发送给你的SD卡路径中的其他人。 此代码使用意图代码是Android默认电子邮件发送屏幕将使用。

通过这种方式,您可以将mms发送给其他人。

现在要保存您发送给其他人的微粒mms,当你开发你创建的屏幕时,你只需捕获整个屏幕......并保存在sd卡中,如...

e.g:

btn_save =(按钮)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自动生成的方法存根

    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();
    }       

}

以上代码将保存您已发送的屏幕,然后只需访问或从您的SD卡特定路径名中获取该图像