-2
私の古いコードはマシュマロで働いていなかったので、このシェアコードを書いた。私はそれをはっきりと混乱させ、結果は得られませんでした。 URLから画像を共有する他の簡単な方法がある場合は、教えてください。共有オプションがマシュマロで働いていない
public void share(View view){
niv1 = (NetworkImageView) findViewById(R.id.imgNetwork);
File file = getLocalBitmapFile(niv1);
Uri bmpUrii = FileProvider.getUriForFile(this, "com.myfileprovider", file);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUrii);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "share");
shareIntent.putExtra(Intent.EXTRA_TEXT, Datas.Address);
startActivity(Intent.createChooser(shareIntent, "Share Image"));
}
public File getLocalBitmapFile(NetworkImageView imageView) {
Drawable drawable = imageView.getDrawable();
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable) {
bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
} else {
return null;
}
File bmpUri = null;
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
私はそれを少し変更しました。助けてください – Sreepulari
私は問題のコードを変更しました、私はそれを編集する必要がある教えてください。 – Sreepulari
@Sreepulari:ビットマップを 'DIRECTORY_DOWNLOADS'に書き出しています。これは、ファイルが 'FileProvider'であるとは言えません。そこに' DIRECTORY_PICTURES'を使っています。 'getLocalBitmapUri()'を 'getLocalBitmapFile()'に名前を変更します。ビットマップを保存している 'File'オブジェクトを返します。同じ 'File'オブジェクトを' getUriForFile() 'と一緒に使用してください。 – CommonsWare