お世話になっております。
質問させて頂きます。
実現したいことは、タイトルの通りです。
AndroidManifest.xml
xml
1 <provider 2 android:name="android.support.v4.content.FileProvider" 3 android:authorities="com.example.app.fileprovider" 4 android:grantUriPermissions="true" 5 android:exported="false"> 6 <meta-data 7 android:name="android.support.FILE_PROVIDER_PATHS" 8 android:resource="@xml/filepaths" /> 9 </provider>
res/xml/filepaths.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<paths xmlns:android="http://schemas.android.com/apk/res/android"> 3 <cache-path name="shared_images/" path="images/"/> 4</paths>
java
1 public void shareWith(String appKeyword, String message) { 2 3 //スクリーンショットを取得 4 Bitmap bitmap = getScreenBitmap(getWindow().getDecorView()); 5 6 try { 7 8 File cachePath = new File(context.getCacheDir(), "images"); 9 cachePath.mkdirs(); // don't forget to make the directory 10 FileOutputStream stream = new FileOutputStream(cachePath + "/image.png"); // overwrites this image every time 11 bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 12 stream.close(); 13 14 } catch (FileNotFoundException e) { 15 e.printStackTrace(); 16 } catch (IOException e) { 17 e.printStackTrace(); 18 } 19 20 File imagePath = new File(context.getCacheDir(), "images"); 21 File newFile = new File(imagePath, "image.png"); 22 Uri contentUri = FileProvider.getUriForFile(context, "com.example.app.fileprovider", newFile); 23 24 25 List<Intent> shareIntentList = new ArrayList<Intent>(); 26 //起動するインテントのリスト 27 List<ResolveInfo> resolveInfoList = 28 getPackageManager().queryIntentActivities( 29 new Intent(Intent.ACTION_SEND).setType("image/png"), 0); 30 //SNSアプリの一覧 31 for(ResolveInfo info : resolveInfoList){ 32 Intent shareIntent = new Intent(Intent.ACTION_SEND).setType( 33 "image/png"); 34 35 if(info.activityInfo.packageName.toLowerCase().contains(appKeyword)){ 36 shareIntent.putExtra(Intent.EXTRA_TEXT, message); 37 shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile( 38 new File(imagePath))); 39 shareIntent.setPackage(info.activityInfo.packageName); 40 shareIntentList.add(shareIntent); 41 } 42 } 43 44 //もし該当するアプリが1つでもあれば起動する 45 if(!shareIntentList.isEmpty()){ 46 47 48 Intent shareIntent = new Intent(); 49 shareIntent.setAction(Intent.ACTION_SEND); 50 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 51 shareIntent.setDataAndType(contentUri, getContentResolver().getType(contentUri)); 52 shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); 53 54 55 shareIntent.putExtra(Intent.EXTRA_STREAM, bitmap); 56 startActivity(Intent.createChooser(shareIntent, "Choose an app")); 57 58 } 59 } 60
と実装しているのですが、
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:560)
こういったエラーがでて落ちてしまいます。
解決策がわからず、、、調査している段階でした。
何かアドバイス等ご教示頂けると幸いです。
よろしくお願い致します。m(_ _)m
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/15 08:21
2016/12/15 11:55
2016/12/15 11:57
2016/12/15 12:00
2016/12/21 09:33
2016/12/21 09:36
2016/12/21 09:37
2016/12/21 10:27
2016/12/26 06:29