2017-10-25 1 views
2

현재 "공유"버튼을 클릭하여 이미지를 공유 할 때 Android 응용 프로그램 자체에서 호출 의도를 만들려고합니다. 내가받은 오류NullPointerException with Android Nougat

Uri uImageFile = FileProvider.getUriForFile(DetailActivity.this, DetailActivity.this.getApplicationContext().getPackageName(), imageFile); 

이되었다 :

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference 
                       at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:584) 
                       at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558) 
                       at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400) 

여기에 전체 코드가 있어요 그러나, 안드로이드 누가 얼마나 공유 텐트 함수의 변화,이 라인에 NullPointerException이 무엇입니까 내 공유 의도 방법 :

private void shareIntent() { 
    Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
    sharingIntent.setType("image/jpg"); 
    File imageFile = new File(data.get(pos).getUrl()); 
    Uri uImageFile = FileProvider.getUriForFile(DetailActivity.this, DetailActivity.this.getApplicationContext().getPackageName(), imageFile); 
    sharingIntent.putExtra(Intent.EXTRA_STREAM, uImageFile); 
    startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.share_to))); 
} 

data.get(pos).getUrl() 내가 그 Parcelable를 구현 만든 사용자 정의 클래스의 URL을 반환하고 때 ou는 인쇄 t를 입력하면 다음과 같은 디렉토리가 반환됩니다. "/storage/emulated/0/Pictures/primitive/Primitive-79538313.jpg"

제공 할 수있는 도움에 감사드립니다!

+0

앱은 외부 저장 장치를 액세스 할 수있는 권한이 있습니까? – Xenolion

+0

예, 나는 프로그램에 다음 권한을 모두 부여했습니다. Rahooligan

답변

0
은 활동에이 코드를 추가하여이

private void shareIntent() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("image/jepg"); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+data.get(pos).getUrl())); 
    startActivity(Intent.createChooser(shareIntent, "Share image")); 
} 

에 코드를 변경

onCreate()

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 
StrictMode.setVmPolicy(builder.build());