我的应用程序创建带附件的邮件,并使用意图Intent.ACTION_SEND来启动邮件应用程序.
它适用于我测试过的所有邮件应用,除了新的Gmail 5.0(适用于Gmail 4.9),邮件打开时没有附件,显示错误:"附件权限被拒绝".
在logcat上没有来自Gmail的有用消息.我只测试了Android KitKat上的Gmail 5.0,但是在多个设备上.
我为附件创建了这样的文件:
String fileName = "file-name_something_like_this";
FileOutputStream output = context.openFileOutput(
fileName, Context.MODE_WORLD_READABLE);
// Write data to output...
output.close();
File fileToSend = new File(context.getFilesDir(), fileName);
Run Code Online (Sandbox Code Playgroud)
我知道安全问题MODE_WORLD_READABLE.
我发送这样的意图:
public static void compose(
Context context,
String address,
String subject,
String body,
File attachment) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(
Intent.EXTRA_EMAIL, new String[] { address });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(attachment));
Intent chooser = Intent.createChooser(
emailIntent,
context.getString(R.string.send_mail_chooser));
context.startActivity(chooser);
}
Run Code Online (Sandbox Code Playgroud)
在创建文件或发送意图时,我有什么问题吗?有没有更好的方法来启动带附件的邮件应用程序?或者 …
我正在寻找一种在android文件系统中临时保存位图文件的方法.只有在将文件用作服务器的POST请求的一部分之后才需要该文件,之后我希望它不再存在.我正在寻找更快的方法.
...
File file = new File(Environment.getExternalStorageDirectory().getPath().toString()+"/ImageDB/" + fileName+".png");
FileOutputStream filecon = new FileOutputStream(file);
sampleResized.compress(Bitmap.CompressFormat.JPEG, 90, filecon);
...
Run Code Online (Sandbox Code Playgroud)
我目前正在使用这种方法.
编辑:我从Android中创建临时文件获得了我的解决方案
在我的应用程序中,用户从库中选择图片并上传.在许多设备上,我的代码工作得很完美,但在新设备上(等:samsung S5,LG G2,Samsung S4)应用程序在选择照片时崩溃.我将应用程序上传到Google Play商店并下载这些设备,然后在应用崩溃时将已发送的报告发送到Google Play.这是我的选择图片和调整代码大小.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), 1);
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleHeight, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, …Run Code Online (Sandbox Code Playgroud) 在我用于流视频的MediaPlayer应用程序中,我使用以下代码
File temp = File.createTempFile("mediaplayertmp", "dat");
Run Code Online (Sandbox Code Playgroud)
在运行它时抛出异常
Parent directory of file in not
writable:/sdcard/
mediaplayertmp43912.dat
Run Code Online (Sandbox Code Playgroud)
我不知道如何处理这个问题,我想知道当我们执行该代码时意味着文件将被创建.任何人都知道解决方案意味着请帮助一些代码.