Android截屏分享

来源:互联网 发布:c语言定义函数并调用 编辑:程序博客网 时间:2024/05/17 02:19

Android截屏并进行分享应该是一个比较好用的功能,可惜在应用中见的不多

1. 截屏

 /**
  * 准备截屏
  */
 public void prepareshoot(){
  try{
   boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
   if (sdCardExist) {
    String rootPath = Environment.getExternalStorageDirectory().getPath()+"/colorgo";
    File imgDir = new File(rootPath);
    if (!imgDir.exists()) {
     Log.v(tag, "logDir.mkdirs()");
     imgDir.mkdirs();
    }
    imgpath = rootPath;
    if(imgpathFile.equals(imgpath + "/colorgoShareImga.png")){
     imgpathFile = imgpath + "/colorgoShareImgb.png";
    }else{
     imgpathFile = imgpath + "/colorgoShareImga.png";
    }
    
   }else{
    Toast.makeText(context, " 存储卡未启用,暂时不能使用该功能。 ", Toast.LENGTH_LONG).show();
   }
  }catch (Exception ex){
   Log.v(tag, "prepareshoot:"+ex.getMessage());
  }
 }

2. 分享,此处的分享仅仅是简单分享,如果要分享到微信等需要二次开发的平台,还需要一系列的操作,比较麻烦

 /**
  * 运行分享
  */
 public void nativeShare(String content)
    {
  try{
         Intent shareIt = new Intent("android.intent.action.SEND");
         shareIt.setType("image/png");
         shareIt.putExtra(Intent.EXTRA_SUBJECT, Constants.appname);     
         shareIt.putExtra(Intent.EXTRA_TEXT, content);
        
         //分享sd卡的图片
         shareIt.putExtra(Intent.EXTRA_STREAM,Uri.parse(imgpathFile));
         shareIt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(Intent.createChooser(shareIt, Constants.appname));
  }catch (Exception ex){
   Log.v(tag, "nativeShare:"+ex.getMessage());
  }
    }

3. 应用场景:经文分享:

比如三字经【http://zhushou.360.cn/detail/index/soft_id/1902511】小应用就是用了截屏分享,经文用于劝人劝己。

 

 

0 0
原创粉丝点击