gpt4 book ai didi

Android 在 snapchat 上分享图片

转载 作者:搜寻专家 更新时间:2023-11-01 08:34:59 27 4
gpt4 key购买 nike

我正在使用此代码来分享乐谱的屏幕截图:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
Uri image = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/sharescore.png");
try {
// create bitmap screen capture
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

File imageFile = new File(image.getPath());

FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
sharingIntent.putExtra(Intent.EXTRA_STREAM, image);
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));

当我使用“imgae/jpeg”类型时,它适用于 Whatsapp Twitter 等,但不适用于 snapchat 和 Instagram。它导致错误“无法打开所选图像”。我怎样才能使它适用于 snapchat 和 instagram。

最佳答案

他们的问题是,我将屏幕截图保存到 sd 卡,但 snapchat 没有从外部存储读取文件的权限。我必须使用只能由我的应用程序访问的应用程序目录,并且必须使用我自己的文件提供程序 (com.test.fileprovider) 更改权限,以便 snapchat 可以访问它。这是代码:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpg");
sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
File newFile = new File(getContext().getCacheDir(), "share_score.jpg");
Log.d(getClass().getSimpleName(), newFile.getAbsolutePath());
Uri image = FileProvider.getUriForFile(getContext(), "com.test.fileprovider", newFile);
try {
// create bitmap screen capture
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

FileOutputStream outputStream = new FileOutputStream(newFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
sharingIntent.putExtra(Intent.EXTRA_STREAM, image);
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));

关于Android 在 snapchat 上分享图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37507693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com