diff --git a/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java b/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java new file mode 100644 index 000000000..ad39af5f2 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/server/ShareBroadcastReceiver.java @@ -0,0 +1,20 @@ +package com.yunbao.common.server; + +import static android.content.Intent.EXTRA_CHOSEN_COMPONENT; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +public class ShareBroadcastReceiver extends BroadcastReceiver { + public static final int REQUEST_CODE = 888; + private static final String TAG = "分享log"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "onReceive"); + Log.i(TAG, intent.getAction() + " | " + intent.getParcelableExtra(EXTRA_CHOSEN_COMPONENT)); + + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/ShareUtil.java b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java index 1f1058449..45416e44f 100644 --- a/common/src/main/java/com/yunbao/common/utils/ShareUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/ShareUtil.java @@ -1,20 +1,53 @@ package com.yunbao.common.utils; +import static android.app.PendingIntent.FLAG_IMMUTABLE; +import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; +import static android.content.Intent.EXTRA_CHOSEN_COMPONENT; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Bitmap; +import android.net.Uri; + +import com.yunbao.common.server.ShareBroadcastReceiver; + +import java.io.File; /** * 分享工具 */ public class ShareUtil { - public static void share(String content) { - share(content, null); + + public static void share(Context context, String content) { + share(context, content, null); } - public static void share(Bitmap bitmap) { - share(null,bitmap); + public static void share(Context context, File image) { + share(context, null, image); } - public static void share(String content, Bitmap bitmap) { + public static void share(Context context, String content, File image) { + Intent shareIntent = new Intent(Intent.ACTION_SEND); + + if (image != null) { + Uri uri = Uri.fromFile(image); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.setType("image/*"); + //当用户选择短信时使用sms_body取得文字 + shareIntent.putExtra("sms_body", content); + } else { + shareIntent.setType("text/plain"); + } + shareIntent.putExtra(Intent.EXTRA_TEXT, content); + //自定义选择框的标题 + PendingIntent pi = PendingIntent.getBroadcast(context, ShareBroadcastReceiver.REQUEST_CODE, + new Intent(context, ShareBroadcastReceiver.class), PendingIntent.FLAG_MUTABLE); + context.registerReceiver(new ShareBroadcastReceiver(),new IntentFilter(EXTRA_CHOSEN_COMPONENT)); + shareIntent = Intent.createChooser(shareIntent, null, pi.getIntentSender()); + context.startActivity(Intent.createChooser(shareIntent, "Share")); + //系统默认标题 } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index f9ae99960..2ffc00e7e 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -3,7 +3,10 @@ package com.yunbao.main.views; import android.animation.ObjectAnimator; import android.app.Dialog; import android.content.Context; +import android.content.Intent; import android.graphics.Outline; +import android.net.Uri; +import android.os.Environment; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -11,6 +14,7 @@ import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.widget.ImageView; +import androidx.core.content.FileProvider; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -36,6 +40,7 @@ import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.ShareUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.CustomViewHolder; import com.yunbao.live.event.LiveRoomChangeEvent; @@ -54,6 +59,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -330,7 +336,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); } @Override @@ -361,6 +367,34 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement .setOnBannerClickListener(new OnBannerClickListener() { @Override public void onBannerClick(List datas, int p) { + if (true) { + System.err.println("cache = " + mContext.getCacheDir().getAbsolutePath()); + String type = "image/*"; + String filename = "/ztest/myPhoto.jpg"; + String mediaPath = Environment.getExternalStorageDirectory() + filename; + // Create the new Intent using the 'Send' action. + Intent share = new Intent(Intent.ACTION_SEND); + + // Set the MIME type + share.setType(type); + + // Create the URI from the media + File media = new File(mediaPath); + Uri uri = FileProvider.getUriForFile(mContext, + mContext.getPackageName() + ".fileprovider", + media + ); + + // Add the URI to the Intent. + share.putExtra(Intent.EXTRA_STREAM, uri); + share.putExtra(Intent.EXTRA_TEXT, "test"); + // Broadcast the Intent. + // share.setPackage("com.whatsapp"); //WhatsApp + + // share = new Intent(Intent.ACTION_VIEW, Uri.parse("https://line.me/R/share?text=test")); //Line + mContext.startActivity(Intent.createChooser(share, "Share to")); + return; + } if (mBannerList != null) { if (p >= 0 && p < mBannerList.size()) { BannerBean bean = mBannerList.get(p); @@ -423,7 +457,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null); } if (!"".endsWith(Constants.mStream)) { - if(MicStatusManager.getInstance().isMic(liveUid)){ + if (MicStatusManager.getInstance().isMic(liveUid)) { MicStatusManager.getInstance().showDownMicDialog(mContext); return; }