0

I am making a basic meme app which I want to send the meme to Snapchat, but I'm getting an error when I try to send it.

My button code to open gallery:

public void onClick(View v) {
  Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  pickIntent.setType("image/* video/*");
  startActivityForResult(pickIntent, MEDIA_RESULT);
}

My onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode== MEDIA_RESULT  && resultCode == RESULT_OK) {
    Uri snapFile = data.getData();
    SnapMediaFactory snapMediaFactory = SnapCreative.getMediaFactory(this);
    SnapPhotoFile photoFile;
    try {
      photoFile = snapMediaFactory.getSnapPhotoFromFile(snapFile);
    } catch (SnapMediaSizeException e) {
      //error
      return;
    }
    SnapPhotoContent snapPhotoContent = new SnapPhotoContent(photoFile);
    snapCreativeKitApi.send(snapPhotoContent);
  }
}

I am getting this error:

http://prntscr.com/msqfp9

statosdotcom
  • 3,109
  • 2
  • 17
  • 40
  • Possible duplicate of [Convert file: Uri to File in Android](https://stackoverflow.com/questions/2975197/convert-file-uri-to-file-in-android). The error is telling you that `snapMediaFactory.getSnapPhotoFromFile()` expects a `java.io.File`, but you're giving it `snapFile`, which is a `android.net.Uri`. – DaveyDaveDave Mar 03 '19 at 21:49
  • @DaveyDaveDave I'm pretty new to this.. I'm trying my best to learn, I really don't understand what I'm doing wrong, it all seems fine to me.. I honestly appreciate any help you can give me, the image/video I select from my button click, should that not be a file and not a uri? What am I doing wrong? – Matthew Smith Mar 03 '19 at 21:59
  • Did you think that if you called your Uri variable name snapFile and it contains "File" word in his name then you can pass the variable as method parameter that require parameter with type File? You must get File from your Uri – Levon Vardanyan Mar 03 '19 at 22:13
  • I'm not an Android developer, so don't know specifics, but that's what the error message is trying to tell you, yeah. It seems that from your `data.getData()` call you get a `Uri`, but the `snapMediaFactory.getSnapPhotoFromFile()` method wants a `File`. Perhaps `snapMediaFactory` has an alternative method that accepts a `Uri`? Or perhaps you can change `data` in some way to get a `File`? If not, then I guess you need to convert it, which is what I think the dupe link above is taking about. – DaveyDaveDave Mar 03 '19 at 22:22
  • I must provide an image or a video to snapMediaFactory, my button allows me to choose that img / vid from gallery, after choosing I want it to send it straight to snapchat. I'm really confused here, is there a way to make my button send the content straight away before it is made to a Uri using this, SnapPhotoContent snapPhotoContent = new SnapPhotoContent(photoFile); ? Sorry for being such an idiot – Matthew Smith Mar 03 '19 at 22:32
  • @DaveyDaveDave I got it working using what you sent, File snapFile1 = new File(getPath(snapFile)); Using the getPath function provided in that answer, but when it sends to snapchat it has an error opening the "image", so I'm guessing whatever file it's sending to snapchat is not an image... how can I make sure it sends an image file? – Matthew Smith Mar 03 '19 at 23:37
  • That sounds like you need to ask a different question. This one is likely to be closed as a duplicate, as the specific error you're asking about is the same issue as the dupe I linked to. Again, I'd strongly recommend taking the [Tour](https://stackoverflow.com/tour) and reading through [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask), which both have lots of useful advice, not just about how to word questions here to help others help you, but also about how to approach debugging so that 9 times out of 10 you'll end up answering your own question before you ask it. – DaveyDaveDave Mar 04 '19 at 10:36

0 Answers0