我正在将CWAC StreamProvider集成到我的代码中,但是运行我的代码后,我看到无法在logcat中获得提供程序com.commonsware.cwac.provider.StreamProvider。我无法从Internet上的解决方案中解决它,因为我发现了一些不适用于我的解决方案。
提供者
<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());
}
错误
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"
您的值是:
cz.revelio.tomiookamura
。private static final String AUTHORITY = "com.anothergamedesigner.CatVimeoTest";
您的值是:
com.anothergamedesigner.CatVimeoTest
。这些值不相同。它们必须相同。
另外,更换:
<assets name="assets" path=""/>
与:
<asset name="assets" path=""/>
关于android - CWAC错误:无法获取提供程序com.commonsware.cwac.provider.StreamProvider,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54206935/