0

im trying to open a Gallery with Images/Videos from a specific Folder. I´m using this solution but im getting the error code below and nothing happens. I guess its something abot the Uri but i cant find a solution. Has anyone an Idea how to solve this? I also included "my" code.

03-15 16:30:53.733 21902-22775/de.comidos.fotoapp D/onScanCompleted: Scan completed: content://media/external/images/media/1730
03-15 16:30:53.752 21902-22775/de.comidos.fotoapp D/Instrumentation: checkStartActivityResult() : Intent { act=android.intent.action.VIEW dat=content://media/external/images/media/1730 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }
03-15 16:30:53.773 21902-22775/de.comidos.fotoapp W/Binder: Binder call failed.
                                                            android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://media/external/images/media/1730 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }
                                                                at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1839)
                                                                at android.app.Instrumentation.execStartActivity(Instrumentation.java:1531)
                                                                at android.app.Activity.startActivityForResult(Activity.java:4389)
                                                                at android.app.Activity.startActivityForResult(Activity.java:4348)
                                                                at android.app.Activity.startActivity(Activity.java:4672)
                                                                at android.app.Activity.startActivity(Activity.java:4640)
                                                                at de.comidos.fotoapp.GalleryViewActivity.onScanCompleted(GalleryViewActivity.java:59)
                                                                at android.media.MediaScannerConnection$1.scanCompleted(MediaScannerConnection.java:55)
                                                                at android.media.IMediaScannerListener$Stub.onTransact(IMediaScannerListener.java:60)
                                                                at android.os.Binder.execTransact(Binder.java:573)

package de.comidos.fotoapp;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import java.io.File;


public class GalleryViewActivity extends Activity implements MediaScannerConnection.MediaScannerConnectionClient {
    public String[] allFiles;
    private String SCAN_PATH ;
    private static final String FILE_TYPE = "*/*";

    private MediaScannerConnection conn;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery);

        File folder = new File(Environment.getExternalStorageDirectory().toString()+"/comidos/sent/");
        allFiles = folder.list();
        //   uriAllFiles= new Uri[allFiles.length];
        for(int i=0;i<allFiles.length;i++)
        {
            Log.d("all file path"+i, allFiles[i]+allFiles.length);
        }
        //  Uri uri= Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString()+"/yourfoldername/"+allFiles[0]));
        SCAN_PATH= Environment.getExternalStorageDirectory().toString()+"/comidos/sent/"+allFiles[0];
        Log.d("SCAN PATH", "Scan Path " + SCAN_PATH);

    }
    private void startScan()
    {
        Log.d("Connected","success"+conn);
        if(conn!=null)
        {
            conn.disconnect();
        }
        conn = new MediaScannerConnection(this,this);
        conn.connect();
    }
    @Override
    public void onMediaScannerConnected() {
        Log.d("onMediaScannerConnected","success"+conn);
        conn.scanFile(SCAN_PATH, FILE_TYPE);
    }
    @Override
    public void onScanCompleted(String path, Uri uri) {
        try {
            Log.d("onScanCompleted","Scan completed: "+uri );
            if (uri != null)
            {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(uri);
                startActivity(intent);
            }
        } finally
        {
            conn.disconnect();
            conn = null;
        }
    }
    @Override
    public void onResume(){
        super.onResume();
        startScan();

    }
}
Community
  • 1
  • 1
TBrauwers
  • 21
  • 1
  • 8

1 Answers1

0

There is no activity on your device that supports ACTION_VIEW of a content Uri for whatever MIME type that content is. There is no requirement for an Android device to have an ACTION_VIEW activity for every possible piece of content.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Are you sure this is the problem here? If i just open a single one with this code: String path = "/storage/emulated/0/comidos/sent/ANFRAGE_4006209501061_357330077957793_2017-03-14-09-07-43-47_001.jpg"; Intent i=new Intent(); i.setAction(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(new File(path)), "image/*"); startActivity(i); It works – TBrauwers Mar 15 '17 at 15:58
  • @TBrauwers: "Are you sure this is the problem here?" -- that is what the exception is telling you. "If i just open a single one with this code" -- whatever activity is responding to that `Intent` supports `file` and not `content` as a scheme. – CommonsWare Mar 15 '17 at 15:59
  • Okay i guess your right... Do you know any solution for my problem(Opening a gallery with a specific folder) I already tried it with an ImageAdapter and a Grid view but this is super slow even on my S7... – TBrauwers Mar 15 '17 at 16:07
  • @TBrauwers: "Do you know any solution for my problem(Opening a gallery with a specific folder)" -- there are hundreds, if not thousands, of gallery apps, and none have to have any ability to start on a particular directory's worth of images. "I already tried it with an ImageAdapter and a Grid view but this is super slow even on my S7" -- my guess is that you did not use an [image loading library](https://android-arsenal.com/tag/46), but that's just a guess. – CommonsWare Mar 15 '17 at 16:10
  • No ive tried the solution from developer.android but thanks for the input ill try it out. – TBrauwers Mar 15 '17 at 16:18