2012-12-10 100 views
1

我想一些文字彩信Android.I这里找到了很多SO以及对谷歌,但仍然没有得到正确的解决方案yet.My代码中附加图片是:如何发送图像附件和Android中的一些文本彩信?

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
      sendIntent.setType("image/png"); 
      sendIntent.putExtra("sms_body", 
        getResources().getText(R.string.Message)); 
      // sendIntent.setType("vnd.android-dir/mms-sms"); 

      Uri mms_uri = Uri.parse("android.resource://" 
        + getPackageName() + "/" + R.drawable.app_logo); 

      sendIntent.putExtra(Intent.EXTRA_STREAM, mms_uri.toString()); 

      startActivity(Intent.createChooser(sendIntent, "")); 

请帮助我为我的这个问题。

+0

你运行当前代码时出现错误? –

+0

没有没有得到任何错误,但我不能附上图像,这是它。我不知道我错了。我可以给你任何关于MMS图像附件的建议吗? – Biginner

回答

0

你有这样的幸运吗?我试过类似的方法,发现

Uri mms_uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.app_logo); 

不通用。我设法通过在资产文件夹中创建映像文件的副本并将其转换为文件来实现。你可以这样做:

File f = new File(getCacheDir()+"/app_logo.png"); 
if (!f.exists()) try { 
    InputStream is = getAssets().open("R.drawable.app_logo"); 
    int size = is.available(); 
    byte[] buffer = new byte[size]; 
    is.read(buffer); 
    is.close(); 

    FileOutputStream fos = new FileOutputStream(f); 
    fos.write(buffer); 
    fos.close(); 
} catch (Exception e) { throw new RuntimeException(e); } 

sharePicture = f.getPath();