CWAC error: Unable to get provider com.commonsware.cwac.provider.StreamProvider

CWAC error: Unable to get provider com.commonsware.cwac.provider.StreamProvider

我正在将 CWAC StreamProvider 集成到我的代码中,但是在 运行 我的代码之后,我看到无法在 logcat 中获取提供程序 com.commonsware.cwac.provider.StreamProvider。我无法从互联网上的解决方案中解决它,因为我只找到了一些不适合我的解决方案。

提供商

     <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>

class

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

OnCreate 方法 为 share

定义了 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=""/>