Choosing photo using new Google Photos app is broken

后端 未结 3 1321
情深已故
情深已故 2020-11-27 12:23

My app has ability to select photo from library. Exactly I want file path from this selection.

This is the code to create intent for selecting photo:



        
3条回答
  •  猫巷女王i
    2020-11-27 12:59

    This is most certainly a workaround, but you could extract the real content URI which has apparently become embedded for some reason: content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F75209

    I was able to create a new URI with authority=media and path=external/images/media/xxx, and content resolver returned a real URL.

    Example code:

    String unusablePath = contentUri.getPath();
    int startIndex = unusablePath.indexOf("external/");
    int endIndex = unusablePath.indexOf("/ACTUAL");
    String embeddedPath = unusablePath.substring(startIndex, endIndex);
    
    Uri.Builder builder = contentUri.buildUpon();
    builder.path(embeddedPath);
    builder.authority("media");
    Uri newUri = builder.build();
    

提交回复
热议问题