Я интегрировал CWAC StreamProvider в свой код, но после запуска своего кода я увидел, что Невозможно получить поставщика com.commonsware.cwac.provider.StreamProvider в logcat. Я не мог решить это из интернет-решений, потому что нашел только несколько решений, которые не работают для меня.
Средний
<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>
Переменные для класса
private static final String AUTHORITY = "cz.revelio.tomiookamura";
private static final Uri PROVIDER = Uri.parse("content://"+AUTHORITY);
private static String ASSET_PATHS;
Метод OnCreate
определенный longClickListener для общего ресурса
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;
}
});
Функции для обмена
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>