无法在Android API 27中查看图片,但在23/22中可见

时间:2018-07-30 11:17:52

标签: java android android-permissions

我是android开发的新手,并从android应用程序的codecanyon购买了源代码,该应用程序下载图像/视频并打开它。 下载可以正常工作,但是当我在带有API 27的模拟器中打开图像时,它没有显示暗屏图像,但是当我在具有API 22/23的模拟器中使用图像时,它仍然可以正常工作

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

enter image description here

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

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();
        }

    }

现在还有一个.java文件,名为“ Imageview.java”

package com.CT.SaveInstaWhatsAppStory;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.startapp.android.publish.ads.banner.Banner;
import com.startapp.android.publish.adsCommon.StartAppSDK;

import config.facebookAudienceNetwork;
import config.startapp;

public class imageview extends AppCompatActivity {

ImageView imageView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.imageview);
    Log.d("TestContent","TestContent");
    if(getSupportActionBar() != null){
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    LinearLayout linearlayout = (LinearLayout)findViewById(R.id.unitads);

    if (getResources().getString(R.string.ads).toLowerCase().equals("1")){
        config.admob.admobBannerCall(this, linearlayout);
    }else if(getResources().getString(R.string.ads).toLowerCase().equals("2")) {

        try{

            StartAppSDK.init(this, startapp.startappID, true);

            Banner startAppBanner = new Banner(this);
            linearlayout.addView(startAppBanner);

        }catch(Exception e){
            e.getStackTrace();
        }
    }else if(getResources().getString(R.string.ads).toLowerCase().equals("3")) {

        try{

            com.facebook.ads.AdView adView = new com.facebook.ads.AdView(this, facebookAudienceNetwork.fbBannerID, com.facebook.ads.AdSize.BANNER_320_50);
            linearlayout.addView(adView);
            adView.loadAd();

        }catch(Exception e){
            e.getStackTrace();
        }

    }
    Log.d("NowOpening1","NowOpening1");
    imageView = (ImageView)findViewById(R.id.imagetoshow);

    try {

        if(getIntent().hasExtra("src")){
            Log.d("NowOpening","NowOpening");
            Picasso.with(this)
                    .load(getIntent().getStringExtra("src")).fit().centerCrop()
                    .into(imageView);


        }else{
            Toast.makeText(this, "ops. nothing to show here!", Toast.LENGTH_SHORT).show();
        }

    }catch(Exception e){
        e.getStackTrace();
    }


}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // app icon in action bar clicked; goto parent activity.
            this.finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
  }
}

这是日志详细信息

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错误)。 另外,我已经在imageview.java中写了Log.d("TestContent","TestContent");,没有被点击。

我不确定这是什么错误以及如何解决,如果有人遇到类似的问题,请告诉我。

我可以在旧版Android(例如4.4,5.1)中看到图像,但看不到7.1和8.0中的图像

Build.Gradle

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

更新Android emulator shows nothing except black screen and adb devices shows "device offline"不是这些问题的重复,因为该问题中的模拟器显示黑屏且根本不起作用,在我看来,模拟器在任何情况下都可以正常工作。

错误与应用有关,在应用中打开图片时,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"

1 个答案:

答案 0 :(得分:0)

如果您要加载存储在SD卡或本地存储中某个位置的图像,则需要在清单文件中添加android.permission.READ_EXTERNAL_STORAGE。但是,如果有,则需要在运行时请求此权限。在低于6的Android上,所有权限均在应用安装过程中授予。从Android 6开始,您需要在运行时询问权限。检查this链接。