1
사용자가 그린 그림을 공유하고 싶습니다. 이 방법은 다음과 같습니다. 먼저 임시 파일을 저장 한 다음 shareintent를 사용하여 파일을 공유합니다. 세부 사항을 다음과 같이Android : 인 텐트를 통해 사진을 공유 할 수 없습니다.
저장 :
private String save_colored_image(String tempName)
{
File f=null;
try
{
colored_image.setDrawingCacheEnabled(true);
colored_image.buildDrawingCache();
Bitmap bimap = colored_image.getDrawingCache();
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
image_file = new File(Environment.getExternalStorageDirectory(), "Abc");
if(!image_file.exists())
{
image_file.mkdirs();
}
if(tempName==null)
{
long seconds = System.currentTimeMillis();
f = new File(image_file.getAbsolutePath()+File.separator+seconds+".jpg");
}
else
f = new File(image_file.getAbsolutePath()+File.separator+tempName+".jpg");
}
FileOutputStream os = new FileOutputStream(f);
bimap.compress(CompressFormat.JPEG, 100, os);
os.close();
if(tempName==null)
{
Toast.makeText(mContext, "Save : "+f.getAbsolutePath(), Toast.LENGTH_SHORT).show();
updateMedia(f.getAbsolutePath());
}
else if (tempName=="shareit")
{
Toast.makeText(mContext, "Sharing...!", Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
if(tempName==null)
Toast.makeText(mContext, "Photo is not saved! Please try again!"+f.getAbsolutePath(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
colored_image.setDrawingCacheEnabled(false);
return f.getAbsolutePath();
}
Shareit :
private void shareit()
{
String filepath = save_colored_image("shareit");
if (filepath!=null && filepath!="")
{
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse(filepath);
File file = new File(phototUri.getPath());
Toast.makeText(mContext, "file path: "+file.getPath(), Toast.LENGTH_SHORT).show();
if(file.exists())
{
// file create success
} else
{
// file create fail
}
shareIntent.setData(phototUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
startActivity(Intent.createChooser(shareIntent, "Share Image Via..."));
}
}
로그 캣 :
06-20 01:08:17.655: W/dalvikvm(17362): threadid=30: thread exiting with uncaught exception (group=0x41ea8700)
06-20 01:08:17.665: E/AndroidRuntime(17362): FATAL EXCEPTION: SyncAdapterThread-1
06-20 01:08:17.665: E/AndroidRuntime(17362): java.lang.NullPointerException
06-20 01:08:17.665: E/AndroidRuntime(17362): at com.google.android.gm.provider.E.a(SourceFile:87)
06-20 01:08:17.665: E/AndroidRuntime(17362): at com.google.android.common.a.onPerformSync(SourceFile:37)
06-20 01:08:17.665: E/AndroidRuntime(17362): at com.google.android.gm.provider.E.onPerformSync(SourceFile:77)
06-20 01:08:17.665: E/AndroidRuntime(17362): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)
06-20 01:08:17.670: I/ActivityManager(2416): Notify an ApplicationCrash
06-20 01:08:17.680: I/dumpstate(17500): begin
질문 :
위의 단지 몇 가지 애플 리케이션을 통해 공유 할 수 있습니다 whatsa와 같은 pp와 Line. 하지만 Gmail에 공유하면 NPE가 중단됩니다. 그 NPE 방아쇠를 당기는 무슨 일이 일어나고 있으며 어떻게 해결 될 수 있습니까?
감사합니다 !!!
은 NPE는 충돌 원인이 무엇 라인을 말해 주는가? –
logcat이 추가되었습니다. Gmail에 트리거 오류가 표시되는 것 같습니다. – pearmak