Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

direct share suggestion feature not implemented for Huawei (P9) #6

Open
chlegou opened this issue Dec 18, 2018 · 2 comments
Open

direct share suggestion feature not implemented for Huawei (P9) #6

chlegou opened this issue Dec 18, 2018 · 2 comments

Comments

@chlegou
Copy link

chlegou commented Dec 18, 2018

it's known that the Nexus share intent add some suggestions for direct share.
Unfortunately, this feature is omitted by Huawei Share.

so from that, i tried your library, so get the same behavior in Huawei devices. but it didn't show the suggested direct share feature.

this could explain: (this is the normal Intent.createChooser() behavior in my phone)

Wanted Result: https://ibb.co/vVJFxH8

result i'm getting: https://ibb.co/qYMWFPt

could you make that as feature?

@zawadz88
Copy link
Owner

Hi,
Direct Share is an Android 6.0+ system feature and I'm not sure if it's possible to have access to the same components which Direct Share uses TBH.
If you have any idea how to add it we can surely discuss this, but to be honest I do not really jave that much time at the moment to investigate this on my own.

This might be a nice enhancement, but a complicated and time consuming to implement.

@chlegou
Copy link
Author

chlegou commented Dec 27, 2018

@zawadz88 It was a challenging, ...but i finally managed to reach it. it appears that android system is able to handle it.

when creating ACTION_SEND intent with ShareCompact and putting it as "EXTRA_INTENT" in ACTION_CHOOSER and sending int to your constructor, i noticed a change comparing to my last code: Previously, it was Android HWResolver before, but with ShareCompact, it was Android System then i realized that something did change, so tried to start the intent normally,

then bingo! it worked like a charm! 😃
the solution didn't need your library, but without the help of it, i wasn't able to reach that result (made me realize the resolver change, was the hint for the solution). thank you ! ;)

i got the solution same day i created the issue, but since i have a lot to work on, didn't have time to get you back :p

i peeked the android source code, these extras looks the keys for such result:

        mIntent.putExtra(EXTRA_CALLING_PACKAGE, launchingActivity.getPackageName());
        mIntent.putExtra(EXTRA_CALLING_ACTIVITY, launchingActivity.getComponentName());

but to reach same behavior, you might need higher minSDK support (API 24), so better to stick with ShareCompact (works for minSDK 15 in my case).

here is the code i'm using for now, giving me the best results i could imagine:
"text/plain" will make it shareable through social media, like hangout, whatsapp, emails, messenger...
"message/rfc822" will make it shareable through emails only.

here is the code that i'm satisfied with:

public static void shareTextViaShareCompactChooser(Activity launcherActivity, String title, String subject, String text){
    Intent shareIntent = ShareCompat.IntentBuilder.from(launcherActivity)
            // the type will force the creation of the sharable text intent
            .setType("text/plain")
            .setSubject(subject)
            .setText(text)
            .getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    Intent intent = new Intent(Intent.ACTION_CHOOSER);
    intent.putExtra(Intent.EXTRA_INTENT, shareIntent);
    intent.putExtra(Intent.EXTRA_TITLE, title);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    }


    launcherActivity.startActivity(intent);
}

public static void sendEmailViaShareCompactChooser(Activity launcherActivity, String title, String mailTo, String subject, String text){
    Intent shareIntent = ShareCompat.IntentBuilder.from(launcherActivity)
            // the type will force the creation of the sharable email intent
            .setType("message/rfc822")
            .setEmailTo(new String[] {mailTo})
            .setSubject(subject)
            .setText(text)
            .getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    Intent intent = new Intent(Intent.ACTION_CHOOSER);
    intent.putExtra(Intent.EXTRA_INTENT, shareIntent);
    intent.putExtra(Intent.EXTRA_TITLE, title);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    }


    launcherActivity.startActivity(intent);
}

Im just posting it here for fun, (i like challenges :p ) and also because you marked it as enhancement.
maybe someone is looking so same behavior, so he could get the solution ;)

Thanks again! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants