diff --git a/Share/src/main/java/com/yunbao/share/AbsShareInterface.java b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java index dbae5135a..141191dbb 100644 --- a/Share/src/main/java/com/yunbao/share/AbsShareInterface.java +++ b/Share/src/main/java/com/yunbao/share/AbsShareInterface.java @@ -3,7 +3,9 @@ package com.yunbao.share; import android.content.Context; import android.content.IntentFilter; import android.net.Uri; +import android.os.Build; +import androidx.annotation.RequiresApi; import androidx.core.content.FileProvider; import com.twitter.sdk.android.tweetcomposer.TweetUploadService; @@ -15,12 +17,22 @@ import java.io.File; public abstract class AbsShareInterface { protected final Context mContext; + public AbsShareInterface(Context context) { this.mContext = context; IntentFilter filter = new IntentFilter(TweetUploadService.UPLOAD_SUCCESS); filter.addAction(TweetUploadService.UPLOAD_FAILURE); filter.addAction(TweetUploadService.TWEET_COMPOSE_CANCEL); - context.registerReceiver(new TwitterResultReceiver(), filter); + + TwitterResultReceiver receiver = new TwitterResultReceiver(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + // Android 12 (API 33) 及以上版本 + context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED); + } else { + // Android 12 (API 33) 以下版本 + context.registerReceiver(receiver, filter); + } } public abstract void share(ShareBean builder, ICallback callback);