Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在android API 27中查看图像,但在23/22中可见_Java_Android_Android Permissions - Fatal编程技术网

Java 无法在android API 27中查看图像,但在23/22中可见

Java 无法在android API 27中查看图像,但在23/22中可见,java,android,android-permissions,Java,Android,Android Permissions,我是android开发新手,从android应用程序的codecanyon购买了源代码,该应用程序下载图像/视频并打开。 下载工作正常,但当我使用API 27在emulator中打开图像时,它会显示黑色屏幕,没有图像,但当我使用API 22/23的emulator时,它工作正常 如下图所示,我正在使用带API 27的Emulator 下面是代码,可能正在加载图像 Allinone.java if(isImage(filepath)){ Log.d("ViewImage","Vi

我是android开发新手,从android应用程序的codecanyon购买了源代码,该应用程序下载图像/视频并打开。 下载工作正常,但当我使用API 27在emulator中打开图像时,它会显示黑色屏幕,没有图像,但当我使用API 22/23的emulator时,它工作正常

如下图所示,我正在使用带API 27的Emulator

下面是代码,可能正在加载图像

Allinone.java

if(isImage(filepath)){
        Log.d("ViewImage","ViewImage");
        try{
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
                List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    activity.grantUriPermission(packageName, MediaURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            }
            intent.setDataAndType(MediaURI, "image/*");
            activity.startActivity(intent);
        }catch (Exception e){
            Toast.makeText(activity , "Sorry. We can't Display Image. please try again" , Toast.LENGTH_LONG).show();
        }

    }
以下是日志详细信息

D/ViewImage: ViewImage
V/FA: Recording user engagement, ms: 6211
V/FA: Connecting to remote service
W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11717000 but found 11580470
V/FA: Activity paused, time: 10356990
D/FA: Logging event (FE): user_engagement(_e),    Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=6211, firebase_screen_class(_sc)=recyclerview, firebase_screen_id(_si)=1513267139711197653}]
  W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
  V/FA: Connecting to remote service
  W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11717000 but found 11580470
 V/FA: Processing queued up service tasks: 2
 E/FA: Failed to send current screen to service
 E/FA: Discarding data. Failed to send event to service

  [ 07-30 16:29:10.212  3298:31514 D/         ]
  HostConnection::get() New Host Connection established 0x8a0d0080, tid 31514
  D/EGL_emulation: eglMakeCurrent: 0xa0c85480: ver 2 0 (tinfo 0xa0c83630)
  W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
  V/FA: Processing queued up service tasks: 0
正如您在日志中看到的,我没有发现任何问题,以前它显示“权限拒绝错误”,但现在没有相关错误(忽略Firebase错误)。 我还编写了
Log.d(“TestContent”,“TestContent”)

我不知道是什么错误和如何解决,如果有人有类似的问题,请让我知道

我可以在旧安卓系统中看到图像,如4.4、5.1,但在7.1和8.0中看不到图像

建造,格雷德尔

apply plugin: 'com.android.application'

 android {
    compileSdkVersion 27
    buildToolsVersion '21.1.2'
    defaultConfig {
    applicationId "com.CT.SaveInstaWhatsAppStory"
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 2
    versionName "0.2"
    testInstrumentationRunner   "android.support.test.runner.AndroidJUnitRunner"
   }
    buildTypes {
        release {
           minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
     }
    }
   productFlavors {
   }
 } //further code removed
更新: 不是这个问题的重复,因为在这个问题中,emulator显示为黑屏&根本不工作,在我的情况下,emulator在所有情况下都工作正常

错误与应用程序有关,当在应用程序中打开图像时,在API 27/28中显示黑屏,而视频显示正确

这是另一个logcat日志,如果这可以进一步澄清我的问题

    07-30 21:07:26.765 1694-4938/system_process W/android.os.Debug: failed to get memory consumption info: -1
    07-30 21:07:26.830 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.834 1694-4338/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.886 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.888 1694-4338/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079

  [ 07-30 21:07:26.907  3298:19560 D/]HostConnection::get() New Host Connection established 0x8668e000, tid 19560
   07-30 21:07:27.001 3298-3298/com.google.android.apps.photos W/View: requestLayout() improperly called by android.widget.FrameLayout{fcc79ff V.E...... ......I. 0,0-1440,2560 #7f0e06c3 app:id/all_controls_container} during layout: running second layout pass
  07-30 21:07:27.025 1694-4338/system_process E/memtrack: Couldn't load memtrack module
  07-30 21:07:27.025 1694-4338/system_process W/android.os.Debug: failed to get memory consumption info: -1
  07-30 21:07:27.121 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16026832 , only wrote 16024320
  07-30 21:07:27.122 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16024326 , only wrote 16024320
  07-30 21:07:27.143 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16025372 , only wrote 16025040
  07-30 21:07:27.239 3298-3298/com.google.android.apps.photos E/BluetoothAdapter: Bluetooth binder is null
 07-30 21:07:27.288 1694-4938/system_process E/memtrack: Couldn't load memtrack module
 07-30 21:07:27.288 1694-4938/system_process W/android.os.Debug: failed to get memory consumption info: -1
 07-30 21:07:27.294 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16032264 , only wrote 16032240
 07-30 21:07:27.294 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16032258 , only wrote 16032240
 07-30 21:07:27.303 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
 07-30 21:07:27.311 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033016 , only wrote 16032960
 07-30 21:07:27.327 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033735 , only wrote 16033680
 07-30 21:07:27.327 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033698 , only wrote 16033680
 07-30 21:07:27.303 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
 07-30 21:07:27.372 1694-4338/system_process W/ActivityManager: Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.google.android.music.dial.DialMediaRouteProviderService} from pid=3298, uid=10069 that is not exported from uid 10064
 07-30 21:07:27.382 1694-28268/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.383 1694-24130/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.386 1694-2806/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.386 1694-24130/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.538 1694-2806/system_process E/memtrack: Couldn't load memtrack module
07-30 21:07:27.538 1694-2806/system_process W/android.os.Debug: failed to get memory consumption info: -1
07-30 21:07:27.553 2467-2808/com.google.android.gms W/MdnsClient_Cast: #acquireLock. Multicast lock not held. Acquiring. Subtypes:"96084372"
07-30 21:07:27.570 2467-2808/com.google.android.gms W/MdnsClient_Cast: Multicast lock held. Releasing. Subtypes:"96084372"
07-30 21:07:27.573 2467-2808/com.google.android.gms W/MdnsClient_Cast: #acquireLock. Multicast lock not held. Acquiring. Subtypes:"96084372"

如果您试图加载存储在SD卡或本地存储器中某处的图像,则需要将
android.permission.READ\u EXTERNAL\u storage
添加到清单文件中。但如果您拥有它,则需要在运行时请求此权限。在低于6的Android上,所有权限都是在应用程序安装期间授予的。从Android 6开始,您需要在运行时请求权限。检查链接。

可能重复否,该错误与Emulator显示黑屏有关我的Emulator工作正常,可以显示视频文件,但无法打开图像文件请不要接受异常,
ex.printStackTrace()
,在这里发布堆栈跟踪。我认为代码已经获得了权限。请动态检查Allinone.java的问题描述代码“如果(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){List resinfo List=activity.getPackageManager().QueryInputActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);对于(ResolveInfo ResolveInfo:ResInfo列表){//获取权限}”此外,我可以下载和查看视频,但无法打开图像,因此如果存在权限问题,视频也不应运行,对吗?您是否阅读了我附加的链接?
grantUriPermission
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},1)
从哪里获取视频?与图像来自同一位置?是的,我阅读了链接,但由于我对android没有太多了解,因此无法实现,您能帮助我在哪里添加此代码吗?是的,从同一位置获取视频,但不能从同一位置获取图像。您是否拥有
android.permission.read\u EXTERNAL\STORAGE
在您的清单中?在低于6(4-5)和>=6的Android上启动您的应用程序,并查看其行为。如果它在低于6的Android上工作,而在高于6的Android上工作不好,则问题在于权限。您使用的目标版本是什么?
    07-30 21:07:26.765 1694-4938/system_process W/android.os.Debug: failed to get memory consumption info: -1
    07-30 21:07:26.830 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.834 1694-4338/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.886 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
   07-30 21:07:26.888 1694-4338/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079

  [ 07-30 21:07:26.907  3298:19560 D/]HostConnection::get() New Host Connection established 0x8668e000, tid 19560
   07-30 21:07:27.001 3298-3298/com.google.android.apps.photos W/View: requestLayout() improperly called by android.widget.FrameLayout{fcc79ff V.E...... ......I. 0,0-1440,2560 #7f0e06c3 app:id/all_controls_container} during layout: running second layout pass
  07-30 21:07:27.025 1694-4338/system_process E/memtrack: Couldn't load memtrack module
  07-30 21:07:27.025 1694-4338/system_process W/android.os.Debug: failed to get memory consumption info: -1
  07-30 21:07:27.121 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16026832 , only wrote 16024320
  07-30 21:07:27.122 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16024326 , only wrote 16024320
  07-30 21:07:27.143 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16025372 , only wrote 16025040
  07-30 21:07:27.239 3298-3298/com.google.android.apps.photos E/BluetoothAdapter: Bluetooth binder is null
 07-30 21:07:27.288 1694-4938/system_process E/memtrack: Couldn't load memtrack module
 07-30 21:07:27.288 1694-4938/system_process W/android.os.Debug: failed to get memory consumption info: -1
 07-30 21:07:27.294 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16032264 , only wrote 16032240
 07-30 21:07:27.294 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16032258 , only wrote 16032240
 07-30 21:07:27.303 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
 07-30 21:07:27.311 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033016 , only wrote 16032960
 07-30 21:07:27.327 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033735 , only wrote 16033680
 07-30 21:07:27.327 1384-2893/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 16033698 , only wrote 16033680
 07-30 21:07:27.303 1694-4938/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
 07-30 21:07:27.372 1694-4338/system_process W/ActivityManager: Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.google.android.music.dial.DialMediaRouteProviderService} from pid=3298, uid=10069 that is not exported from uid 10064
 07-30 21:07:27.382 1694-28268/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.383 1694-24130/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.386 1694-2806/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.386 1694-24130/system_process W/ActivityManager: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{4366e1e 3298:com.google.android.apps.photos/u0a69} (pid=3298, uid=10069) that is not exported from UID 10079
07-30 21:07:27.538 1694-2806/system_process E/memtrack: Couldn't load memtrack module
07-30 21:07:27.538 1694-2806/system_process W/android.os.Debug: failed to get memory consumption info: -1
07-30 21:07:27.553 2467-2808/com.google.android.gms W/MdnsClient_Cast: #acquireLock. Multicast lock not held. Acquiring. Subtypes:"96084372"
07-30 21:07:27.570 2467-2808/com.google.android.gms W/MdnsClient_Cast: Multicast lock held. Releasing. Subtypes:"96084372"
07-30 21:07:27.573 2467-2808/com.google.android.gms W/MdnsClient_Cast: #acquireLock. Multicast lock not held. Acquiring. Subtypes:"96084372"