Android 캡 처 공유 qq 위 챗 기능 구현

지난 글 에서 여러분 께 소개 하 였 습 니 다Android 캡 처 및 공유 기능 구현 코드.관심 이 있 으 면 클릭 하여 읽 을 수 있 습 니 다.오늘 본문 을 통 해 안 드 로 이 드 를 소개 합 니 다.캡 처 공유 qq 위 챗 기능 을 실현 합 니 다.같이 보 자.
머리말
현재 많은 앱 들 이 캡 처 공유 기능 을 가지 고 있 으 니 오늘 은 캡 처 공유 에 대해 이야기 해 보 겠 습 니 다.
오늘 은 다음 과 같은 내용 과 관련된다.
  • Android 캡 처
  • Android 공유
  • 효과 도 전시
  • ok,다음은 구체 적 으로 말씀 드 리 겠 습 니 다.
    권한
    자신의 mainfast 에 다음 권한 을 추가 합 니 다:
    
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    그 다음 에 안 드 로 이 드 7.0 이상 의 권한 을 신청 해 야 한다.전에 말 했 듯 이 여 기 는 더 이상 쓸데없는 말 을 하지 않 는 다.
    캡 처 공유 클래스
    코드 는 다음 과 같 습 니 다:
    
    package com.dialogfragmentdemo.util;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.net.Uri;
    import java.io.File;
    import java.io.FileOutputStream;
    /**
     * Title:    
     * Description:
     *         
     * <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     * <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     *
     * Created by pei
     * Date: 2017/12/6
     */
    public class ShotShareUtil {
     /**    ,     **/
     public static void shotShare(Context context){
     //  
     String path=screenShot(context);
     //  
     if(StringUtil.isNotEmpty(path)){
      ShareImage(context,path);
     }
     }
     /**    **/
     private static String screenShot(Context context){
     String imagePath=null;
     Bitmap bitmap= ScreenUtil.snapShotWithoutStatusBar(context);
     if(bitmap!=null){
      try {
      //       
      imagePath = SDCardUtil.getDiskCachePath()+"share.png";
      LogUtil.e(ShotShareUtil.class, "====imagePath====" + imagePath);
      File file = new File(imagePath);
      FileOutputStream os = new FileOutputStream(file);
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
      os.flush();
      os.close();
      return imagePath;
      } catch (Exception e) {
      LogUtil.e(ShotShareUtil.class, "====screenshot:error====" + e.getMessage());
      }
     }
     return null;
     }
     /**  **/
     private static void ShareImage(Context context,String imagePath){
     if (imagePath != null){
      Intent intent = new Intent(Intent.ACTION_SEND); //          
      File file = new File(imagePath);
      intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));//      
      intent.setType("image/*");//          
      Intent chooser = Intent.createChooser(intent, "Share screen shot");
      if(intent.resolveActivity(context.getPackageManager()) != null){
      context.startActivity(chooser);
      }
     } else {
      ToastUtil.shortShow("   ,   ");
     }
     }
    }
    3.mainactivity 에서 호출
    다음은 예제 코드 입 니 다.
    
    @Override
     public void onClick(View v) {
     super.onClick(v);
     switch (v.getId()) {
      case R.id.button:
      LogUtil.e(MainActivity.class,"====    ====");
      //    
      ShotShareUtil.shotShare(mContext);
      break;
      default:
      break;
     }
     }
    효과 도

    위 는 공유 할 때 핸드폰 에 qq 와 위 챗 이 설치 되 어 있 지 않 은 경우 입 니 다.아래 는 qq,위 챗 이 있 는 경우 입 니 다.

    총결산
    위 에서 말 한 것 은 소 편 이 소개 한 안 드 로 이 드 캡 처 공유 qq 위 챗 기능 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.소 편 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

    좋은 웹페이지 즐겨찾기