1
有人可以帮助我使我的代码存储在缓存而不是我的SD卡。我正在截取我的应用程序的截图,以用于在社交媒体上分享。存储位图在Android缓存中的屏幕截图
// image naming and path to include sd card
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;
// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这里是我的社会化媒体的代码共享截图:
Intent socialIntent = new Intent(Intent.ACTION_SEND);
socialIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = Uri.fromFile(new File(mPath));
socialIntent.putExtra(Intent.EXTRA_STREAM, uri);
socialIntent.setType("image/jpeg");
startActivity(Intent.createChooser(socialIntent, "How do you wanna share?"));
使用Context.getCacheDir()而不是Environment.getExternalStorageDirectory() – Squonk 2011-04-13 15:13:39
我不相信,我可以使用缓存,我的方案。只有我的应用程序才能访问此存储,并且我需要社交媒体才能访问此存储,并且它不会。 – taraloca 2011-04-13 17:44:34
“我需要社交媒体才能访问这个存储,它不会也不会” - 这是正确的,但您的问题是关于不使用SD卡。如果您希望其他应用程序/活动等访问该文件,则必须将其保存在外部存储器(例如SD卡)中。外部存储不适用文件系统权限,但内部内存不会。 – Squonk 2011-04-13 17:49:34