Android 9附加到电子邮件的原始资源不是原始文件
我整个上午都在为一个问题而斗争,我想我现在应该在这里提问了 我使用以下代码将9个修补程序图像附加到电子邮件:Android 9附加到电子邮件的原始资源不是原始文件,android,nine-patch,Android,Nine Patch,我整个上午都在为一个问题而斗争,我想我现在应该在这里提问了 我使用以下代码将9个修补程序图像附加到电子邮件: sendIntent.setType("image/png"); ArrayList<Uri> uris = new ArrayList<Uri>(); uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%
sendIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%05d", mAppBackgroundCurrentFile)) );
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, "Email:"));
我最终将资产复制到SD卡,并使用以下功能将此新文件附加到电子邮件:
...
if( copyAssetToSDCard( filename, basepath + filename ) )
{
uris.add( Uri.parse( "file://" + basepath + filename ) );
}
...
private boolean copyAssetToSDCard( String SrcFilename, String DstFilename )
{
OutputStream out = null;
try
{
AssetManager assetManager = getResources().getAssets();
InputStream in = assetManager.open(SrcFilename);
out = new FileOutputStream(DstFilename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
return true;
}
catch (Exception e)
{
Log.e("copyToSDCard", e.toString());
e.printStackTrace();
}
return false;
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
...
if( copyAssetToSDCard( filename, basepath + filename ) )
{
uris.add( Uri.parse( "file://" + basepath + filename ) );
}
...
private boolean copyAssetToSDCard( String SrcFilename, String DstFilename )
{
OutputStream out = null;
try
{
AssetManager assetManager = getResources().getAssets();
InputStream in = assetManager.open(SrcFilename);
out = new FileOutputStream(DstFilename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
return true;
}
catch (Exception e)
{
Log.e("copyToSDCard", e.toString());
e.printStackTrace();
}
return false;
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}