如何将 android 应用程序中的文本和 link 分享到 Messenger?
How to share text and link from android app to messenger?
我希望能够将一些文本和 link 从我的应用分享到 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);
我只分享这段代码 link:
当我将同一个“ShareLinkContent”分享到 facebook 时,一切正常。谁能帮帮我 :) ?
您可以使用 Intent
class:
共享文本(和 link)
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://whosebug.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
我希望能够将一些文本和 link 从我的应用分享到 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);
我只分享这段代码 link:
当我将同一个“ShareLinkContent”分享到 facebook 时,一切正常。谁能帮帮我 :) ?
您可以使用 Intent
class:
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://whosebug.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