问题描述
到 Android 9,我使用下面的代码并且它正在工作:
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
OutputStream fOut;
Uri outputFileUri;
try {
int time = (int) (System.currentTimeMillis());
Timestamp tstemp = new Timestamp(time);
String timestamp = tstemp.toString();
File root = new File(Environment.getExternalStorageDirectory() + File.separator);
root.mkdirs();
File sdImageMainDirectory = new File(root,timestamp + ".jpg");
outputFileUri = Uri.fromFile(sdImageMainDirectory);
fOut = new FileOutputStream(sdImageMainDirectory);
bm.compress(Bitmap.CompressFormat.PNG,100,fOut);
fOut.flush();
fOut.close();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM,"android.resource://" + getPackageName() + "/drawable/ic_launcher");
sharingIntent.putExtra(Intent.EXTRA_STREAM,outputFileUri);
String shareBody = "Download our app Now";
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"Easy Mobile");
sharingIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
startActivity(Intent.createChooser(sharingIntent,"Share"));
} catch (Exception e) {
e.printstacktrace();
}
从 Android 10 或 11 开始,此代码不起作用。我也获得了运行时权限,并接受了这些权限。但我在 logcat 中看到以下错误: -> content://media/external_primary/file 不允许主目录为空;允许的目录是 [下载、文档] ->java.io.FileNotFoundException:/storage/emulated/0/19691213181944618.jpg:打开失败:EPERM(不允许操作)。
谁能帮我找到合适的解决方案? (java)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)