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

发布于 2024-11-08 23:48:30 字数 2182 浏览 0 评论 0原文

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

我尝试了以下代码,但它给了我异常:异常

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”) 但我在消息中看不到任何彩信。

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.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: Exception removed by removing the line: values.put("body","body 3") But I can't see any mms in messages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赏烟花じ飞满天 2024-11-15 23:48:30

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

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.

卷耳 2024-11-15 23:48:30

彩信正文存储在 content://mms/part/ 中。请参阅此代码了解如何从中读取内容,但请记住所有这些都没有记录,不受支持,并且可能会更改,恕不另行通知。

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.

与他有关 2024-11-15 23:48:30

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

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

然后在这个按钮上编写onclick事件,这将有助于将彩信发送给其他人。

发送彩信代码:

btn_email.setOnClickListener(new View.OnClickListener()
{
@覆盖
公共无效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:"));
                }

            });

这是将从您的 SD 卡路径发送彩信给其他人的代码。
此代码使用意图代码,是 Android 默认电子邮件发送屏幕将使用的。

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

现在要保存您发送给其他人的颗粒彩信,当您开发您创建的屏幕时,您只需捕获整个屏幕...并保存在 SD 卡中,例如...

例如:

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

   });

受保护无效 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 卡特定路径名访问或获取该图像

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文