Android Facebook Share: No Activity Found

I have a problem with my function to post data to Facebook:

    public void postData() {
    try {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setClassName("com.facebook.katana",
                "com.facebook.katana.ShareLinkActivity");
        i.setType("text/*");
        i.putExtra(android.content.Intent.EXTRA_TEXT, "http://sample_url.com");
        startActivity(i);
    } catch (Exception e) {
        Intent i= new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("http://sample_url.com));
        startActivity(i);
    }
}

      

Every time I get information that the activity com.facebook.katana.ShareLinkActivity cannot be started and I have to add code to android manifest. The Facebook app is installed on the phone.

In AndroidManifest.xml:

    <activity android:name="com.facebook.katana.ShareLinkActivity" >
    </activity>

      

LogCat exception:

01-30 14:46:00.903: E/AndroidRuntime(11626): FATAL EXCEPTION: main
01-30 14:46:00.903: E/AndroidRuntime(11626): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.facebook.katana/com.facebook.katana.ShareLinkActivity}; have you declared this activity in your AndroidManifest.xml?
01-30 14:46:00.903: E/AndroidRuntime(11626):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1634)
01-30 14:46:00.903: E/AndroidRuntime(11626):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
01-30 14:46:00.903: E/AndroidRuntime(11626):    at android.app.Activity.startActivityFromChild(Activity.java:3531)
01-30 14:46:00.903: E/AndroidRuntime(11626):    at android.app.Activity.startActivityForResult(Activity.java:3283)
01-30 14:46:00.903: E/AndroidRuntime(11626):    at android.app.Activity.startActivity(Activity.java:3370)

      

+3


source to share


4 answers


Finally, I got this code to work:

        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);

      



Highlights setPackage

and setType

- Android now picks the correct activity from the Facebook package.

+10


source


for all those using appcelerator here's how to make it work ...



var intFB = Ti.Android.createIntent({
                       action : Ti.Android.ACTION_SEND,
                        packageName : "com.facebook.katana",                        
                        type : "text/plain"
                    });                    
                    intFB.putExtra(Ti.Android.EXTRA_TEXT, "http://www.google.com");
                    //facebook only supports LINKS(!!!)
                    Ti.Android.currentActivity.startActivity(intFB);

      

+1


source


Yes ... you have to declare com.facebook.katana.ShareLinkActivity

in the AndroidManifest.xml

file. This must be done.

Edit:

O o ... the problem lies in the method setClassName

. Replace the following line

  i.setClassName("com.facebook.katana","com.facebook.katana.ShareLinkActivity");

      

with this:

   i.setClassName("com.facebook.katana","ShareLinkActivity");

      

As the second parameter in the method className

, and you also passed a package name with a class name that the debugger couldn't find. As the class name is ShareLinkActivity

not com.facebook.katana.ShareLinkActivity

.

This will finally solve your problem.

0


source


It's just that we're all on the same page with this. Facebook deliberately violated this and refuses to fix it and dishonor them for it.

https://developers.facebook.com/bugs/332619626816423

0


source







All Articles