Allrounder
Allrounder

Reputation: 695

When loading image from storage app crashes

I am trying to load an image from storage, but the app crashes and gives me this error:

12-06 22:08:41.539: E/AndroidRuntime(28957): android.content.ActivityNotFoundException:  No Activity found to handle Intent { act=android.intent.action.VIEW  dat=file://android.graphics.Bitmap@429af028file:///storage/emulated/0/My Folder/1417896511752.jpg }
12-06 22:08:41.539: E/AndroidRuntime(28957):    at  android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1660)
12-06 22:08:41.539: E/AndroidRuntime(28957):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)

This is my code I am using

Intent intent = new Intent();
              intent.setAction(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse("file://" + bitmap + fileUri), null);
                startActivity(intent);
            return;
          }
      });

Not sure what i am doing wrong here, as the intent does work if i remove Uri.parse before `("file.....);

Could any one help me please?

Thanks

Upvotes: 0

Views: 76

Answers (3)

Panther
Panther

Reputation: 9408

Try changing this line

intent.setDataAndType(Uri.parse("file://" + bitmap + fileUri), null);

to

intent.setDataAndType(Uri.parse("content://" + bitmap + fileUri),  "image/*");

Upvotes: 1

sleeping_dragon
sleeping_dragon

Reputation: 711

You dont have activity, that is what the error is saying. Maybe you can check for an activity before calling startActivity().

Also, are you sure it works when you remove Uri.parse? Because it should not as setDataAndType expects a URI as data and not a String so it should be an error.

Upvotes: 0

Vigen
Vigen

Reputation: 503

You dont have activity that handles your intent try this instead.

if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

Upvotes: 0

Related Questions