暂存测试几个用intent打开分享的平台
This commit is contained in:
parent
d14939c893
commit
ce8088059a
@ -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));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,53 @@
|
|||||||
package com.yunbao.common.utils;
|
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.graphics.Bitmap;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import com.yunbao.common.server.ShareBroadcastReceiver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分享工具
|
* 分享工具
|
||||||
*/
|
*/
|
||||||
public class ShareUtil {
|
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) {
|
public static void share(Context context, File image) {
|
||||||
share(null,bitmap);
|
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"));
|
||||||
|
//系统默认标题
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package com.yunbao.main.views;
|
|||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Outline;
|
import android.graphics.Outline;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -11,6 +14,7 @@ import android.view.ViewGroup;
|
|||||||
import android.view.ViewOutlineProvider;
|
import android.view.ViewOutlineProvider;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
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.DialogUitl;
|
||||||
import com.yunbao.common.utils.MicStatusManager;
|
import com.yunbao.common.utils.MicStatusManager;
|
||||||
import com.yunbao.common.utils.RouteUtil;
|
import com.yunbao.common.utils.RouteUtil;
|
||||||
|
import com.yunbao.common.utils.ShareUtil;
|
||||||
import com.yunbao.common.utils.ToastUtil;
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
import com.yunbao.common.views.CustomViewHolder;
|
import com.yunbao.common.views.CustomViewHolder;
|
||||||
import com.yunbao.live.event.LiveRoomChangeEvent;
|
import com.yunbao.live.event.LiveRoomChangeEvent;
|
||||||
@ -54,6 +59,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -361,6 +367,34 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement
|
|||||||
.setOnBannerClickListener(new OnBannerClickListener() {
|
.setOnBannerClickListener(new OnBannerClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onBannerClick(List datas, int p) {
|
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 (mBannerList != null) {
|
||||||
if (p >= 0 && p < mBannerList.size()) {
|
if (p >= 0 && p < mBannerList.size()) {
|
||||||
BannerBean bean = mBannerList.get(p);
|
BannerBean bean = mBannerList.get(p);
|
||||||
@ -423,7 +457,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement
|
|||||||
LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null);
|
LiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
if (!"".endsWith(Constants.mStream)) {
|
if (!"".endsWith(Constants.mStream)) {
|
||||||
if(MicStatusManager.getInstance().isMic(liveUid)){
|
if (MicStatusManager.getInstance().isMic(liveUid)) {
|
||||||
MicStatusManager.getInstance().showDownMicDialog(mContext);
|
MicStatusManager.getInstance().showDownMicDialog(mContext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user