简体   繁体   中英

Cannot view image in android API 27 but visible in 23/22

I am new to android development and bought a source code from codecanyon of an android app which downloads image/video and opens it. Downloading is working fine, but when I open image in emulator with API 27 it shows dark screen no image but it works fine when I use emulator with API 22/23

As shown in the below image, I am using Emulator with API 27

在此处输入图片说明

Here is the code, which is probably loading image

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

    }

Now there is one more .java file which is named as "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);
    }
  }
}

Here is the log details

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

As you can see in the Log, I don't find any issue, previously it was showing "Permission denied error" but there isn't related error (Ignore Firebase error) now. Also I have written Log.d("TestContent","TestContent"); in imageview.java which is not being hit.

I am not sure what's the error and how to solve, if anybody has got similar issue, please let me know.

I can see images in old android like 4.4 , 5.1 but cannot see images in 7.1 and 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

UPDATE: Android emulator shows nothing except black screen and adb devices shows "device offline" is not duplicate of this questions , as in this question emulator is showing black screen & not working at all, in my case emulator is working fine in all situations.

Error is related to app, when opening Images in app it is showing black screen in API 27/28 while videos are shown properly.

Here is another logcat logs, if this can clarify my issue more

    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"

If you are trying to load image, which is stored somewhere on SD-card or local storage, you need to add android.permission.READ_EXTERNAL_STORAGE to your manifest file. But if you have it, you need to ask for this permission in runtime. On Android below 6 all permissions were granted during app installation. Beginning from Android 6,you need to ask the permission at runtime. Check this link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM