方法一:
private void share() { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.setType("text/plain"); startActivity(sendIntent); }
方法二:
ShareSDK.initSDK(B2_ProductDetailActivity.this); initImagePath(); showShare(false, null, dataModel.goodDetail.goods_name + " \n来自#" + getString(R.string.app_name) + "Android客户端# " + goods_url,goods_url);
private void initImagePath() { try { if (Environment.MEDIA_MOUNTED.equals(Environment .getExternalStorageState()) && Environment.getExternalStorageDirectory().exists()) { TEST_IMAGE = Environment.getExternalStorageDirectory() .getAbsolutePath() + FILE_NAME; } else { TEST_IMAGE = getApplication().getFilesDir().getAbsolutePath() + FILE_NAME; } File file = new File(TEST_IMAGE); if (!file.exists()) { file.createNewFile(); String url =dataModel.goodDetail.img.small; // Bitmap pic = BitmapFactory.decodeResource(getResources(), // R.drawable.saomiao); Bitmap pic =getImage(url); FileOutputStream fos = new FileOutputStream(file); pic.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } } catch (Throwable t) { t.printStackTrace(); TEST_IMAGE = null; } } // 获取指定路径的图片 public static Bitmap getImage(String urlpath) throws Exception { URL url = new URL(urlpath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5 * 1000); Bitmap bitmap = null; if (conn.getResponseCode() == 200) { InputStream inputStream = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } return bitmap; }
private void showShare(boolean silent, String platform, String content,String tid) { OnekeyShare oks = new OnekeyShare(); // 分享时Notification的图标和文字 oks.setNotification(R.drawable.logo, getString(R.string.app_name)); oks.setTitle(getString(R.string.share)); // titleUrl是标题的网络链接,仅在人人网和QQ空间使用 oks.setTitleUrl(tid); // text是分享文本,所有平台都需要这个字段 oks.setText(content); // imagePath是图片的本地路径,Linked-In以外的平台都支持此参数 oks.setImagePath(TEST_IMAGE); // oks.setImageUrl(dataModel.goodDetail.img.small); // url仅在微信(包括好友和朋友圈)中使用 oks.setUrl(tid); // comment是我对这条分享的评论,仅在人人网和QQ空间使用 oks.setComment(getString(R.string.share)); // site是分享此内容的网站名称,仅在QQ空间使用 oks.setSite(getString(R.string.app_name)); // siteUrl是分享此内容的网站地址,仅在QQ空间使用 oks.setSiteUrl(tid); // oks.setVenueName("Southeast in China"); // oks.setVenueDescription("This is a beautiful place!"); oks.setSilent(silent); if (platform != null) { oks.setPlatform(platform); } // 去除注释,则快捷分享的分享加过将听过OneKeyShareCallback回调 // oks.setCallback(new OneKeyShareCallback()); // oks.setShareContentCustomizeCallback(new // ShareContentCustomizeDemo()); oks.show(this); }