String time = null; public void shareScreenshot() { time = "rival_" + DateUtils.getTimeNow(); shot(); new Thread(new Runnable() { public void run() { Intent intent = new Intent("android.intent.action.SEND"); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "我正在使用应用,赶快分享给大家吧!"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Constant.path + time + ".png"))); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); LoginActivity.this.startActivity(Intent.createChooser(intent, "分享")); }
}).start(); }
public void shareIcon() {
time = "rival_" + DateUtils.getTimeNow(); FileUtils.savePic( BitmapFactory.decodeResource(getResources(), R.drawable.icon), time); new Thread(new Runnable() { public void run() { Intent intent = new Intent("android.intent.action.SEND"); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "我正在使用应用,赶快分享给大家吧!"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Constant.path + time + ".png"))); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); LoginActivity.this.startActivity(Intent.createChooser(intent, "分享")); }
}).start(); }
* 截屏方法 * * @return */ private Bitmap shot() { View view = getWindow().getDecorView(); Display display = this.getWindowManager().getDefaultDisplay(); view.layout(0, 0, display.getWidth(), display.getHeight()); view.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(view.getDrawingCache()); view.destroyDrawingCache(); FileUtils.savePic(bmp, time); return bmp; }
|