Android Question Java online Share Facebook / Twitter / Gmail / etc..

MarcoRome

Expert
Licensed User
Longtime User
Hi all, i found this interesting code:

B4X:
// code of share(String nameApp,String imagePath,String message) function
public void share(String nameApp, String imagePath, String message) {
    try {
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/jpeg");
        List<ResolveInfo> resInfo = getPackageManager()
                .queryIntentActivities(share, 0);
        if (!resInfo.isEmpty()) {
            for (ResolveInfo info : resInfo) {
                Intent targetedShare = new Intent(
                        android.content.Intent.ACTION_SEND);
                targetedShare.setType("image/jpeg"); // put here your mime
                                                        // type
                if (info.activityInfo.packageName.toLowerCase().contains(
                        nameApp)
                        || info.activityInfo.name.toLowerCase().contains(
                                nameApp)) {
                    targetedShare.putExtra(Intent.EXTRA_SUBJECT,
                            "Sample Photo");
                    targetedShare.putExtra(Intent.EXTRA_TEXT, message);
                    targetedShare.putExtra(Intent.EXTRA_STREAM,
                            Uri.fromFile(new File(imagePath)));
                    targetedShare.setPackage(info.activityInfo.packageName);
                    targetedShareIntents.add(targetedShare);
                }
            }
            Intent chooserIntent = Intent.createChooser(
                    targetedShareIntents.remove(0), "Select app to share");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    targetedShareIntents.toArray(new Parcelable[] {}));
            startActivity(chooserIntent);
        }
    } catch (Exception e) {
        Log.v("VM",
                "Exception while sending image on" + nameApp + " "
                        + e.getMessage());
    }
}

For attaching image on gmail,facebook,twitter with text use below code.
File filePath = new File("your image path");
share("gmail",filePath.toString(),"your comment");
share("facebook",filePath.toString(),"your comment");
share("twitter",filePath.toString(),"your comment");

But when i compile i have error about List<Intent>...

Any idea ?
Thank's
Marco
 

MarcoRome

Expert
Licensed User
Longtime User
Hi thedesoltesoul...
the question is share Facebook.
I have this code that work without problem Whatsapp, Twitter, etc. but dont work with facebook.

B4X:
    Dim i As Intent , uri, testo As String
            uri="********************" & CRLF &"Condiviso con:" & CRLF & "https://play.google.com/store/apps/details?id=xxxxx"
            testo = "Inseriamo un testo corto da pochi caratteri..."
            i.Initialize(i.ACTION_SEND, "")          
              i.SetType("text/plain")
            i.PutExtra("android.intent.extra.SUBJECT", Activity.Title  )      
            i.PutExtra("android.intent.extra.TEXT", testo &  CRLF & uri)
              i.WrapAsIntentChooser("Share")
              StartActivity(i)

I try also AhaShare but i see that want Facebookid and RedirectUri ( i reading tutorial NJDude https://www.b4x.com/android/forum/threads/tutorial-post-to-facebook-wall-via-b4a-app.17739/#content but now Fb want https as RedirectUrl)

The question is... exist one intent or similar code that can i use for share in FB ??

Thank you
Marco
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Yes i see this that more or less is same thing. These filters are applications that you would like to use. Example: I want to share only with Gmail +, FB, WhatsApp, Twitter.
Do you know exist code to share in FB without use AhaShare ( it's a fantastic library ) ??
 
Upvote 0

Similar Threads

Top