2017-08-10 24 views
1

内部ディレクトリからファイルを共有したいと思います。 私は既にファイルプロバイダを使用しています。Android共有ファイル

 <provider 
     android:name="android.support.v4.content.FileProvider" 
     android:authorities="com.gps.stuttgartuni.bincalendar" 
     android:exported="true" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/file_path" /> 
    </provider> 

と私はコードがクライアントでGmailのを使用して構築した電子メールを送信すると問題がないの.xml を送信しようとしています。この

  File file = new File(getFilesDir(), fileName); 
    if(file.exists()){ 
     try { 
      Uri uri =FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID, file); 
      Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
      sharingIntent.setType("application/xml"); 

      sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); 
      sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
      Context context=getApplicationContext(); 
      List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY); 
      for (ResolveInfo resolveInfo : resInfoList) { 
       String packageName = resolveInfo.activityInfo.packageName; 
       context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); 
      } 
      startActivity(sharingIntent); 
     } 
     catch (Exception e){ 
      Log.e("Error",e.getMessage()); 
     } 

などのファイルを共有し、私は」することができますアプリやメッセンジャー、その他のメッセージングアプリを使用してファイルを共有できます。 同じメッセンジャーアプリは、フォーマットがサポートされていないというトーストを表示しますが、通常はそれらを使用して.xmlファイルを送信できます。

なぜコードにはいくつかのアプリでのみ問題があるのですか?

答えて

0

これは、あなたがsharingIntent.setType("application/xml");に設定されているため、すべてのアプリがあなたの意図を処理できないためです。タイプをsharingIntent.setType("text/plain");

+0

に変更してください。私はまた、これを引き起こすファイルをコッピングすることに別の問題がありました。ありがとう。 – GosiaK

+0

あなたは大歓迎です! –

関連する問題