내부 저장 장치에 저장되어있는 스크린 샷을 공유하고 싶지만 공유 중에는 빈 화면이 나타납니다. 나는 다른 앱이 개인 정보를 얻은 앱을 사용할 수 없다는 것을 알게되었다.내부 저장 장치의 스크린 샷을 공유하십시오.
File path = new File(getApplicationContext().getDir("Default", Context.MODE_ENABLE_WRITE_AHEAD_LOGGING),"myapp");
File directory = new File(path.getAbsolutePath());
directory.mkdirs();
String filename = "myapp.png";
File yourFile = new File(directory, filename);
try
{
FileOutputStream out = new FileOutputStream(yourFile, true);
bitmap.compress(Bitmap.CompressFormat.PNG, 90,out);
out.flush();
out.close();
send(yourFile);
}catch (IOException e)
{
e.printStackTrace();
}
그리고 공유 의도입니다 : 이것은 내가 이미지를 저장하는 데 사용했던 코드입니다
public void send(File path)
{
Uri uri = Uri.fromFile(path);
Log.d("uri", String.valueOf(path));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "My App");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share via"));
}
이미지가 저장지고 경로의 값이있는 경로 :
/data/user/0/com.sample.myapp/app_Default/myapp/myapp.png
이제 스크린 샷에 액세스하여 공유 할 수있는 방법을 확인합니다.
나는 귀하의 코드를 구현했으며 위의 코드를 편집했습니다. 이제 코드를 실행하면 앱이 추락합니다. 내가 어디로 잘못 가고 있니? –
예외는 무엇입니까? – Sach
이것은 내가 얻는 것입니다 "java.lang.NullPointerException : 인터페이스 메소드 'boolean android.database.Cursor.moveToFirst()'를 null 객체 참조에 호출하려고 시도 함" –