update Share

This commit is contained in:
zlzw 2023-02-09 10:04:13 +08:00
parent 3c80038bef
commit 15b232f52a
4 changed files with 38 additions and 19 deletions

View File

@ -1,7 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yunbao.share"> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
<queries><provider android:authorities="com.facebook.katana.provider.PlatformProvider" /></queries> xmlns:tools="http://schemas.android.com/tools"
package="com.pdlive.shayu">
<queries>
<package android:name="com.pdlive.shayu"/>
<package android:name="com.facebook.orca"/>
<package
android:name="com.facebook.composer" />
<package
android:name="com.facebook.katana" />
<package
android:name="com.facebook.messenger" />
<provider
android:authorities="com.facebook.katana.provider.PlatformProvider"
tools:ignore="ExportedContentProvider" />
</queries>
<application android:allowBackup="true"> <application android:allowBackup="true">
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" />
<provider <provider
android:name="com.facebook.FacebookContentProvider" android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider2011402032399020" android:authorities="com.facebook.app.FacebookContentProvider2011402032399020"

View File

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import com.facebook.CallbackManager; import com.facebook.CallbackManager;
import com.facebook.FacebookCallback; import com.facebook.FacebookCallback;
import com.facebook.FacebookException; import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.share.Sharer; import com.facebook.share.Sharer;
import com.facebook.share.model.ShareLinkContent; import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.model.SharePhoto; import com.facebook.share.model.SharePhoto;
@ -25,25 +26,20 @@ public class MessengerShare extends AbsShareInterface {
public MessengerShare(Context context) { public MessengerShare(Context context) {
super(context); super(context);
FacebookSdk.setIsDebugEnabled(true);
} }
@Override @Override
public void share(ShareBuilder builder, ICallback callback) { public void share(ShareBuilder builder, ICallback callback) {
callbackManager = CallbackManager.Factory.create(); callbackManager = CallbackManager.Factory.create();
/* ShareLinkContent content = new ShareLinkContent.Builder() ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(builder.getLink())) .setContentUrl(Uri.parse(builder.getLink()))
.build();*/
SharePhoto photo = new SharePhoto.Builder()
.setImageUrl(fileToUri(builder.getFile()))
.build();
SharePhotoContent content=new SharePhotoContent.Builder()
.addPhoto(photo)
.build(); .build();
MessageDialog dialog = new MessageDialog((Activity) mContext); MessageDialog dialog = new MessageDialog((Activity) mContext);
dialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { dialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override @Override
public void onSuccess(Sharer.Result result) { public void onSuccess(Sharer.Result result) {
ToastUtil.show("Messenger分享成功"); ToastUtil.show("Messenger分享成功:"+result.getPostId());
} }
@Override @Override
@ -57,7 +53,6 @@ public class MessengerShare extends AbsShareInterface {
e.printStackTrace(); e.printStackTrace();
} }
}); });
ToastUtil.show(dialog.canShow(content)+" <");
dialog.show(content); dialog.show(content);
} }
} }

View File

@ -162,8 +162,8 @@ dependencies {
api 'cn.rongcloud.sdk:im_kit:5.2.5.4' // UI api 'cn.rongcloud.sdk:im_kit:5.2.5.4' // UI
// //
api 'cn.rongcloud.sdk:sight:5.2.5.4' api 'cn.rongcloud.sdk:sight:5.2.5.4'
api 'com.facebook.android:facebook-android-sdk:15.0.1' api 'com.facebook.android:facebook-android-sdk:15.2.0'
implementation 'com.facebook.android:facebook-android-sdk:15.0.1' implementation 'com.facebook.android:facebook-android-sdk:15.2.0'
api('com.twitter.sdk.android:twitter-core:3.1.1@aar') { api('com.twitter.sdk.android:twitter-core:3.1.1@aar') {
transitive = true transitive = true

View File

@ -45,8 +45,8 @@ public class TestActivity extends AppCompatActivity {
File media = new File(mediaPath); File media = new File(mediaPath);
ShareBuilder builder = new ShareBuilder() ShareBuilder builder = new ShareBuilder()
.setFile(media) .setFile(media)
.setLink("http://blog.yutou233.cn") .setLink("https://www.baidu.com")
.setText("测试Test http://blog.yutou233.cn"); .setText("测试Test https://www.baidu.com");
ICallback callback = new ICallback() { ICallback callback = new ICallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
@ -96,7 +96,7 @@ public class TestActivity extends AppCompatActivity {
@Override @Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
Log.i("分享log", "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); Log.i("分享log", "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data.getAction() + "]");
if (FacebookShare.callbackManager != null) { if (FacebookShare.callbackManager != null) {
FacebookShare.callbackManager.onActivityResult(requestCode, resultCode, data); FacebookShare.callbackManager.onActivityResult(requestCode, resultCode, data);
} else if (MessengerShare.callbackManager != null) { } else if (MessengerShare.callbackManager != null) {