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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yunbao.share">
<queries><provider android:authorities="com.facebook.katana.provider.PlatformProvider" /></queries>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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">
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider2011402032399020"
@ -10,9 +34,9 @@
android:name="com.yunbao.share.receiver.TwitterResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS" />
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE" />
<action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL" />
</intent-filter>
</receiver>
</application>

View File

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

View File

@ -45,8 +45,8 @@ public class TestActivity extends AppCompatActivity {
File media = new File(mediaPath);
ShareBuilder builder = new ShareBuilder()
.setFile(media)
.setLink("http://blog.yutou233.cn")
.setText("测试Test http://blog.yutou233.cn");
.setLink("https://www.baidu.com")
.setText("测试Test https://www.baidu.com");
ICallback callback = new ICallback() {
@Override
public void onSuccess() {
@ -96,7 +96,7 @@ public class TestActivity extends AppCompatActivity {
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent 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) {
FacebookShare.callbackManager.onActivityResult(requestCode, resultCode, data);
} else if (MessengerShare.callbackManager != null) {