Android - 分享至其他APP


調用分享窗:
public static void shareMsg(Context context,String msgText,String imgPath) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                if (imgPath == null || imgPath.equals("")) {
                        intent.setType("text/plain"); // 纯文本
                } else {
                        File f = new File(imgPath);
                        if (f != null && f.exists() && f.isFile()) {
                                intent.setType("image/*");
                                Uri u = Uri.fromFile(f);
                                intent.putExtra(Intent.EXTRA_STREAM, u);
                        }
                }
                intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
                intent.putExtra(Intent.EXTRA_TEXT, "我在用分享!");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(Intent.createChooser(intent, "分享"));
        }

留言

這個網誌中的熱門文章

Android - 輸入字串排除 使用InputFilter

Android - OkHttp3連線 post應用