I'm trying to create an art source ( plugin ) for muzei.
The app is supposed to provide a new art source which in my case is a folder of my app-private space.
Following the example from the muzei api here and the details it provides here I created a FileProvider for my app.
I have added this code to my manifest :
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.foo.bar.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/muzei_wallpapers" />
</provider>
I created the xml file muzei_wallpapers
in my res/xml folder :
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="files/" />
</paths>
and as you can see it points to my files/
folder.
And last is my class that extends MuzeiArtSource
:
public class MuzeiService extends MuzeiArtSource {
Uri imgUri;
public MuzeiService() {
super(MuzeiService.class.getName());
}
@Override
public void onCreate() {
super.onCreate();
// setUserCommands(BUILTIN_COMMAND_ID_NEXT_ARTWORK); // manual switch image
}
@Override
protected void onUpdate(int arg0) {
imgUri = muzeiContentUri();
publishArtwork(new Artwork.Builder()
.imageUri( Uri.parse("imgUri") )
.title("Example image")
.byline("Unknown person, c. 1980")
.build());
}
public Uri muzeiContentUri() {
File imagePath = new File(getFilesDir(), "files");
File newFile = new File(imagePath, "wallpaper0.png");
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.foo.bar.fileprovider", newFile);
return contentUri;
}
}
Which seems to me the simplest example I can have returning the uri for a simple file ( named wallpapaper0 )
When I select as resource for muzei my app I get an "unfortunately muzei has stopped" and the logcat is :
05-28 04:29:40.350: E/AndroidRuntime(3670): FATAL EXCEPTION: IntentService[TaskQueueService]
05-28 04:29:40.350: E/AndroidRuntime(3670): java.lang.NullPointerException
05-28 04:29:40.350: E/AndroidRuntime(3670): at com.google.android.apps.muzei.util.IOUtil.readFullyWriteToOutputStream(IOUtil.java:210)
05-28 04:29:40.350: E/AndroidRuntime(3670): at com.google.android.apps.muzei.util.IOUtil.readFullyWriteToFile(IOUtil.java:202)
05-28 04:29:40.350: E/AndroidRuntime(3670): at com.google.android.apps.muzei.ArtworkCache.maybeDownloadCurrentArtworkSync(ArtworkCache.java:122)
05-28 04:29:40.350: E/AndroidRuntime(3670): at com.google.android.apps.muzei.TaskQueueService.onHandleIntent(TaskQueueService.java:56)
05-28 04:29:40.350: E/AndroidRuntime(3670): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
05-28 04:29:40.350: E/AndroidRuntime(3670): at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 04:29:40.350: E/AndroidRuntime(3670): at android.os.Looper.loop(Looper.java:137)
05-28 04:29:40.350: E/AndroidRuntime(3670): at android.os.HandlerThread.run(HandlerThread.java:61)
I would really appreciate any help cause I'm stuck with it the last days and I feel like I'm missing something simple here...