carsten-klaffke / send-intent

Repository for send-intent Capacitor plugin
MIT License
106 stars 12 forks source link

Can't add informations to my intent using putExtra #60

Closed Lineaum closed 1 year ago

Lineaum commented 1 year ago

Hello, first of all thanks for this package, I was close to giving up when I found it. i'm using Ionic 6.2, Capacitor 4.

I added two activities, each having it's intent-filter in my app on Android side for now. Indeed, I would like to have 2 buttons in the Android ShareSheet triggering two different scenarios for the files I share.

image

I thought about using putExtra for each intent and set a 'verb' so that when my app lauches I can check the value of this 'verb' and determine what to do accordingly (scenario 1 or 2).

image

However even with the intent having a putExtra to it the structure of the intent when calling checkSendIntentReceived() stays the following (thanks to an JSON.stringify of the result) :

image

And that's it, I thought I could retrieve the 'verb' into the additionalItems of the Intent's interface but it ain't there. Or maybe could I use the description field and how ?

For now I'm going to have only one button in the ShareSheet, so only one activity and intent. I will add a page in my app asking the user which scenario he wants to be done with the file but for a future update it would be awesome to be able to have both ! :)

carsten-klaffke commented 1 year ago

Hello!

I think the "extra"-attribute isn't read by the plugin. Unfortunately, "description" works only for iOS. You could use either one of "type", "title" or "url", where each has some logic how it is read by the plugin. So look at SendIntent.java to understand how the values will be evaluated! You could also branch/PR if you want to add and use "description" instead. I am not 100% sure if it will display two buttons on the ShareSheet, but I'd try to define two activities in the AndroidManifest.xml. Then, to distinguish between these two activities in the plugin, I would derive two classes from SendIntentActivity.java and link them in the corresponding AndroidManifest.xml-activity. Like that:

<activity
            android:name=".yourpackage.Activity1"
...

An activity itself should then look like this:

package yourpackage;

import android.content.Intent;

import de.mindlib.sendIntent.SendIntentActivity;

public class Activity1 extends SendIntentActivity {

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        intent.setType("add");
    }

}

As I said, using "type" would be just an option. It would override file types and you might need them.

I hope this helps you and works out.

Best regards Carsten

Lineaum commented 1 year ago

Hi, thanks for the quick answer,

I'm sorry I was unclear the two buttons already works fine with defining two activities yes ! ;) However, the activities's classes are quite empty for now and it's working. The activity and the intent-filter themselves in the manifest generate an intent, right (or I didn't understood this part of Android doc ^^') ? . Indeed, I've put everything from "public void OnCreate" in my 2nd screenshot into comment and everything is still working. I will have a look into SendIntentAcitivity.java and refactor my activities to make sure it keeps on working in the future.

I could also try intent.setType(intent.getType + ":add") ? So by reading this string until ':' I can retrieve the original type and the part after gives me the extra information. I have checked the MIME type for the files type I need (image, pdf, doc & docx) and ':' ain't used so it could work fine. I will give it a try !

carsten-klaffke commented 1 year ago

Hey Lineaum, did you succeed? If so, please close this ticket!

Lineaum commented 1 year ago

Yep everything is working fine for Android, I'm closing it now, thanks again for the help and the reminder