Android 캡 처 공유 qq 위 챗 기능 구현
머리말
현재 많은 앱 들 이 캡 처 공유 기능 을 가지 고 있 으 니 오늘 은 캡 처 공유 에 대해 이야기 해 보 겠 습 니 다.
오늘 은 다음 과 같은 내용 과 관련된다.
권한
자신의 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 위 챗 기능 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.소 편 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.