作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试共享 ImageView 中显示的图像。但是分享时黑屏,提交时提示“分享失败”
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CAMERA" />
代码如下
collageImage.setImageBitmap(bmap1);
Drawable mDrawable = collageImage.getDrawable();
Bitmap bitmap = ((BitmapDrawable)mDrawable).getBitmap();
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.png");
cachePath.mkdirs();
try {
cachePath.createNewFile();
FileOutputStream ostream = new FileOutputStream(cachePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/DCIM/Camera/image.png"));
Intent openThree = new Intent(createChooser(share, "Share Image"));
startActivity(openThree);
Toast.makeText(v.getContext(), "Selected: ", Toast.LENGTH_LONG).show();
日志猫
06-18 13:47:36.906 4429-4429/com.austurn.keikonew.keiko W/System.err: java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:280)
at java.io.File.createNewFile(File.java:948)
06-18 13:47:36.907 4429-4429/com.austurn.keikonew.keiko W/System.err: at com.austurn.keikonew.keiko.ThreeFragment$10.onClick(ThreeFragment.java:2122)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
06-18 13:47:36.909 4429-4429/com.austurn.keikonew.keiko W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
06-18 13:47:36.911 4429-4429/com.austurn.keikonew.keiko W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
06-18 13:47:37.034 4429-4440/com.austurn.keikonew.keiko I/art: Background partial concurrent mark sweep GC freed 1063(81KB) AllocSpace objects, 0(0B) LOS objects, 3% free, 122MB/126MB, paused 26.566ms total 119.644ms
06-18 13:47:37.121 4429-4452/com.austurn.keikonew.keiko D/EGL_emulation: eglMakeCurrent: 0xa43052a0: ver 3 1 (tinfo 0xa43032a0)
06-18 13:47:40.471 4429-4452/com.austurn.keikonew.keiko D/EGL_emulation: eglMakeCurrent: 0xa43052a0: ver 3 1 (tinfo 0xa43032a0)
Gradle详情如下
compileSdkVersion 28
defaultConfig {
applicationId "com.austurn.keikonew.keiko"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
它在以前的版本和 Android Studio 早期版本中工作。但问题发生在版本更新之后
最佳答案
对于上面的代码,您需要应用运行时读写权限,并且您的目标是牛轧糖,这就是为什么您需要使用文件提供程序应用读取路径权限。并且需要在 Android Manifest 中注册 provider
检查这个link
关于android - 来自 ImageView 的图像在共享时仅显示黑色图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50905789/
我是一名优秀的程序员,十分优秀!