0

I am sharing mp3 file to another application by CWAC-Provider https://github.com/commonsguy/cwac-provider This file is sharing on longClick. After longclick I get filepath from array and call method to create Intent for sharing. In this Intent I call getUri function for find my file. All works without error, application show box to choose target application. But when I choose Gmail I have error: Max size of file is 20MB, Discord shows only message but no file and Telegram unsupported attachment. I don't know where is the problem. This provider is not my cup of tea, but I red documentation.

function getUri

      private Uri getURI(){
    return(PROVIDER
            .buildUpon()
            .appendPath(StreamProvider.getUriPrefix(AUTHORITY))
            .appendEncodedPath(ASSET_PATHS)
            .build());
}

This function returns:

    content://cz.revelio.tomiookamura/ea12dd4a-c098-4ce5-b191- 
   abab9d00b52f/assets/nase_hnuti_spd.mp3

I have all my mp3 in assets folder.

provider_paths.xml

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <asset name="asset" path=""/>
    </paths>

Set onLongClick()

     button.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        Bundle params = new Bundle();
                        params.putInt("ButtonId", v.getId());
                        String btnName = "share_"+soubor;
                        mFirebaseAnalytics.logEvent(btnName, params);
                        ASSET_PATHS =  "assets/"+soubor+".mp3";
                        Log.e("ERROR","Path:"+getURI());


                        return false;
                    }
                });

function onShareFile

    private void onShareFile() {


   Intent shareIntent = new Intent();
   shareIntent.setAction(Intent.ACTION_SEND);
   shareIntent.putExtra(Intent.EXTRA_TEXT, "Poslechni si hlášku Tomia Okamury z aplikace Hlášky Tomia Okamury!");
   shareIntent.putExtra(Intent.EXTRA_STREAM, getURI());
   shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
   shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION );
   shareIntent.setType("audio/*");
   startActivity(Intent.createChooser(shareIntent, "Sdílet hlášku"));
  }

Provider in manifest

    <provider
        android:name="com.commonsware.cwac.provider.StreamProvider"
        android:authorities="cz.revelio.tomiookamura"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

define class variables

private static final String AUTHORITY = "cz.revelio.tomiookamura";
private static final Uri PROVIDER = Uri.parse("content://"+AUTHORITY);
private static String ASSET_PATHS;

1 Answers1

0
ASSET_PATHS =  "assets/"+soubor+".mp3";

Here, you have the path as having assets/.

<asset name="asset" path=""/>

Here, you have name as asset.

These do not match, and they need to match.

Beyond that, you should consider writing yourself an instrumented test, where you attempt to read this content from your own provider, and ensure that you are getting a byte-for-byte match.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Now I have ASSET_PATHS = "asset/"+soubor+".mp3"; but nothing changed – TheGoldTiger Jan 17 '19 at 17:54
  • @Knihaman: Write an instrumented test. Confirm that your provider is serving up what it is supposed to be. Look for error messages in Logcat from the other apps and see if they tell you anything. – CommonsWare Jan 17 '19 at 18:19