在我的应用程序中,用户可以拍照或向应用程序添加照片。当应用程序尝试在ImageView中显示保存的图像时,我会收到java.lang.SecurityException的崩溃报告
错误所在的线路是
holder.imageV.setImageURI(uriParsed);
我无法在我的设备或模拟器上复制错误,它们都能很好地显示图像。
我使用的完整代码是
JoinProjectPicture projectPicture = mProjects.get(position);
Project current = projectPicture.getProject();
Picture picture = projectPicture.getPicture();
holder.projectName.setText(current.getProjectName() + "(" + current.getWidth() + "x" + current.getHeight() + ")");
holder.projectStatusTV.setText(current.getStatus());
if(picture != null) {
String pictureName = picture.getPictureName();
Uri uriParsed = Uri.parse(pictureName);
if(uriParsed != null) {
Log.d("URIParsed", "Project: " + current.getProjectName() + " - Parsed: " + uriParsed);
holder.imageV.setImageURI(uriParsed);
}
}
我的设备上显示的日志输出(3个项目,一个没有图像)
项目:测试-已解析:file:///storage/emulated/0/Android/data/com.desbrina.diamondpaintinglogbook/files/Pictures/20191111_1408166491573472523237896.jpg
项目:测试3-已解析:content://com.android.providers.media.documents/document/image:1891
错误
java.lang.SecurityException:
at android.os.Parcel.createException (Parcel.java:1966)
at android.os.Parcel.readException (Parcel.java:1934)
at android.os.Parcel.readException (Parcel.java:1884)
at android.app.IActivityManager$Stub$Proxy.getContentProvider (IActivityManager.java:4039)
at android.app.ActivityThread.acquireProvider (ActivityThread.java:6365)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider (ContextImpl.java:2825)
at android.content.ContentResolver.acquireUnstableProvider (ContentResolver.java:1835)
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1449)
at android.content.ContentResolver.openAssetFileDescriptor (ContentResolver.java:1302)
at android.content.ContentResolver.openAssetFileDescriptor (ContentResolver.java:1225)
at android.graphics.ImageDecoder$ContentResolverSource.createImageDecoder (ImageDecoder.java:273)
at android.graphics.ImageDecoder.decodeDrawableImpl (ImageDecoder.java:1652)
at android.graphics.ImageDecoder.decodeDrawable (ImageDecoder.java:1645)
at android.widget.ImageView.getDrawableFromUri (ImageView.java:952)
at android.widget.ImageView.resolveUri (ImageView.java:921)
at android.widget.ImageView.setImageURI (ImageView.java:532)
at android.support.v7.widget.AppCompatImageView.setImageURI (AppCompatImageView.java:116)
at com.desbrina.diamondpaintinglogbook.ui.main.Adapters.ProjectListAdapter.onBindViewHolder (ProjectListAdapter.java:88)
at com.desbrina.diamondpaintinglogbook.ui.main.Adapters.ProjectListAdapter.onBindViewHolder (ProjectListAdapter.java:23)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.dispatchLayout (RecyclerView.java:3641)
at android.support.v7.widget.RecyclerView.onLayout (RecyclerView.java:4194)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.support.constraint.ConstraintLayout.onLayout (ConstraintLayout.java:1915)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.support.v4.view.ViewPager.onLayout (ViewPager.java:1775)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1565)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:323)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1565)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:323)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1565)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:323)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout (DecorView.java:1088)
at android.view.View.layout (View.java:22406)
at android.view.ViewGroup.layout (ViewGroup.java:6594)
at android.view.ViewRootImpl.performLayout (ViewRootImpl.java:3417)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2884)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1932)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8589)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:949)
at android.view.Choreographer.doCallbacks (Choreographer.java:761)
at android.view.Choreographer.doFrame (Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:935)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7094)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:975)
Caused by: android.os.RemoteException:
at com.android.server.am.ActivityManagerService.getContentProviderImpl (ActivityManagerService.java:15677)
at com.android.server.am.ActivityManagerService.getContentProviderImpl (ActivityManagerService.java:15586)
at com.android.server.am.ActivityManagerService.getContentProvider (ActivityManagerService.java:16151)
at android.app.IActivityManager$Stub.onTransact$getContentProvider$ (IActivityManager.java:11035)
at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:295)
此异常通常是由使用来自第三方应用程序的Imageuri引起的。解决方案是实现文件提供程序。您可以获得许多关于如何实现文件提供程序的解决方案。
从Api24
,您不能直接访问文件URI。您需要使用文件夹的文件权限,然后使用
val photoURI = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", File(path));
在安德罗德马尼菲斯。xml
将以下内容添加到应用程序
标签。在下面的包名是BuildConfig。APPLICATION_ID
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="packagename.provider"
android:enabled="true"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
提供者路径。xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
</paths>
我认为你在AndroidPie或更高版本的操作系统上遇到了安全异常。这是因为在这些系统上,你必须声明你的应用程序想要使用的路径。
请检查:https://developer.android.com/reference/android/support/v4/content/FileProvider
此外,您的应用程序可能正试图从另一个需要Google照片所需权限的应用程序获取内容:
检查这个:java。lang.SecurityException:权限拒绝:打开提供程序com.google.Android应用程序。照片。所容纳之物谷歌图片提供商
我想为AWS Elasticache(Redis)创建一个安全组。 据我所知,我有两种选择: 在端口6379上打开自定义传输控制协议,并定义可以到达Redis的IP地址作为源。 或者,当前有效的方法是:我将 6379 端口打开到任何位置(以便我的 EC2 实例可以连接到它),并在 EC2 之前保护组件。 这里最好的方法是什么?
我试图建立一个Barebonds Hello World安全示例。但我总是出错。 下面是我的web.xml: org.springframework.beans.factory.beanCreationException:创建名为“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
我在多线程环境中做的工作很少。所以,我需要知道below类的getInstance函数是否是线程安全的。这是单例类: 在getInstance函数(未注释)中,返回静态对象的引用。它需要线程安全机制吗? 在第二个getInstance(注释)中,如果singleObject为null,我们就创建对象。所以,它需要锁定机制,需要同步,对吧?
Kubernetes 提供了多种机制来限制容器的行为,减少容器攻击面,保证系统安全性。 Security Context:限制容器的行为,包括 Capabilities、ReadOnlyRootFilesystem、Privileged、RunAsNonRoot、RunAsUser 以及 SELinuxOptions 等 Pod Security Policy:集群级的 Pod 安全策略,自动为集
问题内容: 如果我有一个下面定义的Java类,则通过依赖项注入将其插入我的Web应用程序中: 我担心线程安全。Spring框架是否不能处理一个请求正在从列表中读取而当前正在被另一个请求更新的情况?我以前在其他应用程序中使用过读/写锁,但是我之前从未考虑过这种情况。 我打算将bean作为单例使用,以便减少数据库负载。 顺便说一下,这是以下问题的跟进: Java内存存储以减少数据库负载-安全吗? 编辑
问题内容: 我写了下面的Singleton类。我不确定这是否是线程安全的单例类吗? 谁能帮我这个?我在上述Singleton课堂上的任何想法都会有很大帮助。 更新代码: 我正在尝试将波希米亚建议纳入我的代码中。这是更新的代码,我得到了- 谁能看一下,让我知道这次是否正确? 问题答案: 但是有一个简单的技巧,可以让你的代码是线程安全的实现,并不需要同步!它称为“ 按需初始化持有人”习惯用法,它看起来