-2
많은 골칫거리를 덜어주기 위해 다음과 같은 방법으로 앱에이 기능을 추가 할 수 있습니다.캐시를 사용하여 whatsapp와 이미지 및 텍스트 공유하기
많은 골칫거리를 덜어주기 위해 다음과 같은 방법으로 앱에이 기능을 추가 할 수 있습니다.캐시를 사용하여 whatsapp와 이미지 및 텍스트 공유하기
이 문제에 문제가있어서 해결책을 찾기까지 몇 시간이 걸리지 만 다음과 같은 사항이 효과가 있습니다. 당신의 활동
Picasso.with(context)
.load("http://...")
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
try {
File myDir = new File(getCacheDir() + "/pictureToShare.jpg");
FileOutputStream out = new FileOutputStream(myDir);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
} catch(Exception e){
// some action
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
}
);
File requestFile = new File(getCacheDir() + "/pictureToShare.jpg");
Uri imageUri = FileProvider.getUriForFile(YourActivity.this,
getPackageName() + ".share", requestFile);
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_TEXT,"Your text"); //to share text
share.putExtra(Intent.EXTRA_STREAM, imageUri); //to share image
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(share);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
를 삽입 AndroidManifest.xml에이 코드에
코드 (당신은 오픈 소스 피카소 라이브러리 필요)
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.share"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
폴더를 만듭니다 "res"폴더에 "xml"이라는 이름으로 "provider_paths"라는 이름의 XML 리소스 파일이 있습니다. provider_paths.xml에 다음 줄을 씁니다.
<paths>
<cache-path name="name" path="." />
</paths>