title: Install .APK from Android Cache
body: <p>I have problems installing an APK saved in Android internal Cache. 
  There are no issues saving the file in External Storage or on External Cache using <strong>context.getExternalCacheDir()</strong>.</p>
  
  <p>But if I try to use <strong>context.getCacheDir()</strong>, the log returns</p>
  
  <p><em><strong>/data/data/com.my.package/cache/update.apk: open failed: EACCES (Permission denied)</em></strong></p>
  
  <pre><code>                File file = context.getCacheDir();
  
                  File outputFile = new File(file, "update.apk");
                  if(outputFile.exists()){
                      outputFile.delete();
                  }
  
                  FileOutputStream fos = new FileOutputStream(outputFile);
  
  
                  InputStream is = c.getInputStream();
  
                  byte[] buffer = new byte[1024];
                  int len1 = 0;
                  while ((len1 = is.read(buffer)) != -1) {
                      fos.write(buffer, 0, len1);
                  }
                  fos.close();
                  is.close();
  
                  Intent intent = new Intent(Intent.ACTION_VIEW);
  
                  //SAVE IN CACHE
                  intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
  
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
                  context.startActivity(intent);
  </code></pre>
  
  <p>It looks like internal cache doesn't allow the APK to be correctly read. </p>
  
  <p>The fact is, if the file is saved on the External Storage or external Cache the APK will be available to the user, and I don't want that. </p>
  
  <p>What can it be don to save the file in internal Cache?</p>
  
  <p>Thanks</p>