title: Android: loading bitmap from local storage into app widget (RemoteViews)
body: <p>Until now I've been loading a bitmap into my <code>RemoteViews</code> directly using <code>remoteViews.setImageViewBitmap()</code>.  It's working fine in general.</p>
  
  <p>But a couple of users are having issues, and I think it is when loading in a bitmap that is very large.  I cache the bitmap to local storage already anyway, so my idea is to use <code>setImageViewUri()</code> instead, as recommended elsewhere.</p>
  
  <p>But I can't get it to work... I just get a blank widget.  The following snippet illustrates what I'm doing (leaving out some the context but hopefully leaving enough)...</p>
  
  <pre><code>// Bitmap bmp is fetched from elsewhere... and then...
  
  FileOutputStream fos = context.openFileOutput("img.png", Context.MODE_PRIVATE);
  bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
  fos.flush();
  fos.close();
  
  // ... later ...
  
  // this works...
  remoteViews.setImageViewBitmap(R.id.imageView, bmp);
  
  // but this doesn't...
  remoteViews.setImageViewUri(R.id.imageView, Uri.fromFile(new File(context.getFilesDir().getPath(), "img.png")));
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Trying to use <code>FileProvider</code> as suggested by CommonsWare below...</p>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="com.xyz.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true"&gt;
      &lt;meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/file_paths" /&gt;
  &lt;/provider&gt;
  </code></pre>
  
  <p>xml/file_paths.xml:</p>
  
  <pre><code>&lt;paths xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;files-path name="cache" path="."/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>File imagePath = new File(context.getFilesDir(), ".");
  File newFile = new File(imagePath, "img.png"); // img.png created as above, in top level folder
  remoteViews.setImageViewUri(R.id.imageView, FileProvider.getUriForFile(context, "com.xyz.fileprovider", newFile));
  </code></pre>
  
  <p>But still I'm left with a blank widget, as before, and without an error in the logcat.</p>