Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建Android意图在facebook上共享?_Android_Facebook_Button_Android Intent_Share - Fatal编程技术网

如何创建Android意图在facebook上共享?

如何创建Android意图在facebook上共享?,android,facebook,button,android-intent,share,Android,Facebook,Button,Android Intent,Share,我不明白哪里出了错 我基本上是在尝试这样做,当我点击“fb”按钮时,应用程序通过包含链接在facebook上打开一个共享,但一旦我测试,它就会打开没有链接的facebook页面? 你能帮我吗? 我想知道你是否也可以输入一个固定的文本和链接(如果可能的话,你可以看到我的代码行)? 谢谢 这是密码 final Button button = (Button) findViewById(R.id.fb); button.setOnClickListener(new View.OnClickListen

我不明白哪里出了错 我基本上是在尝试这样做,当我点击“fb”按钮时,应用程序通过包含链接在facebook上打开一个共享,但一旦我测试,它就会打开没有链接的facebook页面? 你能帮我吗? 我想知道你是否也可以输入一个固定的文本和链接(如果可能的话,你可以看到我的代码行)? 谢谢

这是密码

final Button button = (Button) findViewById(R.id.fb);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        String urlToShare = "https://www.google.it/?gfe_rd=cr&ei=IysDVMyHPMjD8gesvYH4DA";
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect!
        intent.putExtra(Intent.EXTRA_TEXT, urlToShare);

        // See if official Facebook app is found
        boolean facebookAppFound = false;
        List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
        for (ResolveInfo info : matches) {
            if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) {
                intent.setPackage(info.activityInfo.packageName);
                facebookAppFound = true;
                break;
            }
        }

        // As fallback, launch sharer.php in a browser
        if (!facebookAppFound) {
            String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
        }

        startActivity(intent);
final Button Button=(按钮)findviewbyd(R.id.fb);
setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
字符串urlToShare=”https://www.google.it/?gfe_rd=cr&ei=IysDVMyHPMjD8gesvYH4DA";
意向意向=新意向(意向.行动\发送);
intent.setType(“文本/普通”);
//intent.putExtra(intent.EXTRA_SUBJECT,“Foo bar”);//注意:无效!
intent.putExtra(intent.EXTRA_TEXT,urlToShare);
//查看是否找到Facebook官方应用程序
布尔facebookAppFound=false;
列表匹配项=getPackageManager().QueryInputActivities(intent,0);
对于(ResolveInfo:matches){
if(info.activityInfo.packageName.toLowerCase().startsWith(“com.facebook.katana”)){
intent.setPackage(info.activityInfo.packageName);
facebookAppFound=true;
打破
}
}
//作为备用方案,在浏览器中启动sharer.php
如果(!facebookAppFound){
字符串sharerUrl=”https://www.facebook.com/sharer/sharer.php?u=“+urlToShare;
intent=newintent(intent.ACTION_视图,Uri.parse(sharerUrl));
}
星触觉(意向);

以下代码适用于您可以共享的所有社交网络:

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT,urlToShare);
        startActivity(Intent.createChooser(sharingIntent,"Şhare"));
以下是错误链接:

问题是,如果你把一个URL放在额外的文本字段中,它会起作用。就像他们故意删除任何文本一样

编辑:
最新的Facebook版本不允许您使用意图共享文本。您必须使用Facebook SDK来实现这一点-为了简单起见,请使用Facebook SDK+Android simple Facebook()。

谢谢,但只支持Facebook?我想立即开始Facebook检查我的编辑…也可以查看此链接
The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields.