0

i want to open Facebook app inside my application and it will show on Imageview On click event. i have referred 10-20 links tried all of them but nothing works for me. i don want to use Facebook default image button, i want to do it on imageview click event.

i have tried links:

and many more

After trying everything my current code is:

 public void shareFacebook() {
    String fullUrl = "https://m.facebook.com";
    try {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setPackage ("com.facebook.katana");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");
        context.startActivity(sharingIntent);

    } catch (Exception e) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(fullUrl));
        context.startActivity(i);

    }
}

Manifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="1975812626048291"/>
    <provider
        android:name="com.facebook.FacebookContentProvider"
    android:authorities="com.facebook.app.FacebookContentProvider1975812626048291"
    android:exported="true" />
    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity android:theme="@style/AppTheme" android:name="com.facebook.katana.FacebookLoginActivity"
        android:permission="com.facebook.permission.prod.FB_APP_COMMUNICATION" android:exported="false"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="stateHidden|adjustResize" />

Dependencies

 implementation 'com.facebook.android:facebook-login:4.33.0'

showing version should be same as recycler view version but putting the same version it is still not working.

 jcenter()
    mavenCentral()
    maven { url 'https://jitpack.io'}

describe proper way to implement and also i have put that imageview on recyclerview so please whatever u suggest it should be on onBindViewHolder() of recyclerview.

and current error is:

Unable to find explicit activity class {com.facebook.katana/com.facebook.katana.ShareLinkActivity}; have you declared this activity in your AndroidManifest.xml?

i dont know how to describe activity of facebook in manifest .. and do we need another java activity just to open app inside our application?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • check this https://stackoverflow.com/q/4191492/7666442 and https://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app – AskNilesh Jan 28 '19 at 06:57

3 Answers3

0

I think the problem is that you have no setType. Try this example.

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
    sharingIntent.setPackage("com.facebook.katana");
    startActivity(sharingIntent);
Ivan Abakumov
  • 128
  • 1
  • 13
-1

open FB App without using facebook SDk this was my requirement of this question

reference link

Share image and text through Whatsapp or Facebook

 Intent FBIntent = new Intent(Intent.ACTION_SEND);
    FBIntent.setType("text/plain");
    FBIntent.setPackage("com.facebook.katana");
    FBIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
    try {
        context.startActivity(FBIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(context, "Facebook have not been installed.", Toast.LENGTH_SHORT).show( );
    }

works fine for instagram, twitter also, just need to change the package name.

-1

This method works for me. Check it out. I took the method from here

protected void OpenFacebookPage(){

     // facebook page id
     String facebookPageID = "dempagumi.inc";

     // URLs
     String facebookUrl = "https://www.facebook.com/" + facebookPageID;

     // URL scheme
     String facebookUrlScheme = "fb://page/" + facebookPageID;

     try {
         // Get Facebook app version
         int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;

         if (versionCode >= 3002850) {
             // For Facebook app version 11.0.0.11.23 (3002850) or higher
             Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
             startActivity(new Intent(Intent.ACTION_VIEW, uri));
         } else {
             // If Facebook app is old
             startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrlScheme)));
         }
     } catch (PackageManager.NameNotFoundException e) {
         // If Facebook app is not installed, open in browser
         startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));

     }

 }
Ivan Abakumov
  • 128
  • 1
  • 13
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/34743751) – moken Jul 26 '23 at 04:26
  • Thanks @moken I have edited the answer – Ivan Abakumov Jul 26 '23 at 12:44