title: Open a file on Android Version 28 and above
body: <p>I am trying to open a remote file using following code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>if (isAndroid) {
      const context = utils.ad.getApplicationContext();
      try {
          if (this.isExternalStorageAvailable() &amp;&amp; !this.isExternalStorageReadOnly()) {
              const fsa = new FileSystemAccess();
              const mimeTypeMap = android.webkit.MimeTypeMap.getSingleton();
              const mimeType = mimeTypeMap.getMimeTypeFromExtension(fsa.getFileExtension(filePath).replace(".", "").toLowerCase());
              const intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
              intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
              intent.setDataAndType(android.net.Uri.fromFile(new java.io.File(filePath)), mimeType);
  
              context.startActivity(android.content.Intent.createChooser(intent, "Open File..."));
  
              return true;
          } else {
              // TODO: no external storage access logic
          }
      } catch (e) {
          console.log(e);
          //traceWrite("Error in openFile", traceCategories.Error, traceMessageType.error);
      }
      return false;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>However when I run this code on Android Version 28 and above, I get following exception. </p>
  
  <p>Error: android.util.AndroidRuntimeException: Calling <code>startActivity()</code> from outside of an Activity  context requires the <code>FLAG_ACTIVITY_NEW_TASK</code> flag. Is this really what you want?</p>
  
  <p>When I further checked the exception, <a href="https://stackoverflow.com/questions/3918517/calling-startactivity-from-outside-of-an-activity-context">here</a> I found that resolution of issue provided at given link. However by performing setFlag/addFlag does not resolve my issue. Another solution provided is to get Activity Context instead of Application context. Can someone guide me on how to resolve this issue? </p>