我希望可以共享一些文本并将其从我的应用程序链接到Messenger,并获得如下消息: (消息来自Elephant Evolution应用共享)
这是我的代码:
//SHARING TO FACEBOOK
String photoURL = "https://play.google.com/";
if(!mEvent.getPhotoUrl().isEmpty()){
photoURL=mEvent.getPhotoUrl();
}
String quoteToShare = "someText";
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(photoURL))
.setQuote(quoteToShare)
.build();
//ShareDialog.show(EventActivity.this,content);
MessageDialog.show(EventActivity.this, content);
使用此代码,我仅共享链接:
当我与Facebook共享相同的“ ShareLinkContent”时,一切正常。谁能帮助我:)吗?
答案 0 :(得分:1)
您可以使用Intent
类共享文本(和链接):
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
String textToShare = "My own text\nhttps://stackoverflow.com/";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
button.setOnClickListener(v -> {
try {
startActivity(sendIntent);
} catch (Exception ex) {
ex.printStackTrace();
}
});
}
}
Facebook Messenger的软件包为:com.facebook.orca