我在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);
    }
}

每次我得到无法运行activity com.facebook.katana.sharelinkactivity的信息时,我都应该向android清单中添加代码。手机上安装了Facebook应用程序。
在androidmanifest.xml中:
    <activity android:name="com.facebook.katana.ShareLinkActivity" >
    </activity>

logcat中的异常:
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)

最佳答案

最后我得到了这个代码:

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

要点是setPackagesetType-现在android从facebook包中选择了正确的活动。

09-10 12:37
查看更多