I was integrating CWAC StreamProvider to my code, but after run my code, I saw Unable to get provider com.commonsware.cwac.provider.StreamProvider in logcat. I couldn't solve it from solutions on internet, because I found only a few solutions which not works for me.
Provider
<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>
Variables for class
private static final String AUTHORITY = "cz.revelio.tomiookamura";
private static final Uri PROVIDER = Uri.parse("content://"+AUTHORITY);
private static String ASSET_PATHS;
OnCreate method defined longClickListener for share
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);
AssetManager assetManager = getAssets();
ASSET_PATHS = "assets/" + soubor+".mp3";
setShareIntent();
return false;
}
});
Functions for share
private Intent setShareIntent(){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/*");
shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""});
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hláška");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
shareIntent.putExtra(Intent.EXTRA_STREAM, getURI());
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
return shareIntent;
}
private Uri getURI(){
return(PROVIDER
.buildUpon()
.appendPath(StreamProvider.getUriPrefix(AUTHORITY))
.appendPath(ASSET_PATHS)
.build());
}
Error
2019-01-15 22:32:54.081 29858-29858/cz.revelio.tomiookamura E/AndroidRuntime: FATAL EXCEPTION: main
Process: cz.revelio.tomiookamura, PID: 29858
java.lang.RuntimeException: Unable to get provider com.commonsware.cwac.provider.StreamProvider: java.lang.IllegalArgumentException: Failed to parse com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS meta-data
at android.app.ActivityThread.installProvider(ActivityThread.java:5856)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: Failed to parse com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS meta-data
at com.commonsware.cwac.provider.StreamProvider.attachInfo(StreamProvider.java:208)
at android.app.ActivityThread.installProvider(ActivityThread.java:5853)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: Could not build strategy for assets
at com.commonsware.cwac.provider.StreamProvider.parseStreamStrategy(StreamProvider.java:418)
Provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<assets name="assets" path=""/>
</paths>
android:authorities="cz.revelio.tomiookamura"
Your value here is: cz.revelio.tomiookamura
.
private static final String AUTHORITY = "com.anothergamedesigner.CatVimeoTest";
Your value here is: com.anothergamedesigner.CatVimeoTest
.
These values are not the same. They need to be the same.
Also, replace:
<assets name="assets" path=""/>
with:
<asset name="assets" path=""/>