title: How to open .xlsx files in Android?
body: <p>I wrote app a few months ago. I had Note 2 with Android Kitkat(and it was ok). My friends were testing (and now they are using it) and everything is okay.</p>
  
  <p>I bought new phone with Android Nougat (7.0) .
  Now I can't open .xlsx file.
  I use this method when click the button.</p>
  
  <pre><code>private void ReadXLSX() {
      nameFILE= "OOOO.xlsx";
      Intent target = new Intent(Intent.ACTION_VIEW);
      target.setDataAndType(Uri.fromFile(new File((getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS))+"/"+ nameFILE)), "application/vnd.ms-excel");
      target.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
      Log.v("OPEN_FILE_PATH", getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/" + nameFILE);
     startActivity(target);
  </code></pre>
  
  <p>When I use debbuger :
  I am here, after that crash</p>
  
  <pre><code>try {
                  mResolvedMethod.invoke(mResolvedContext, v);
              } catch (IllegalAccessException e) {
                  throw new IllegalStateException(
                          "Could not execute non-public method for android:onClick", e);
              } catch (InvocationTargetException e) {
                  throw new IllegalStateException(
                          "Could not execute method for android:onClick", e);
              }
  </code></pre>
  
  <p>My AndroidManifest.xml has:</p>
  
  <pre><code>   &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>-------------EDIT-------------
  LOGCAT</p>
  
  <pre><code> 04-15 23:20:57.073 22020-22020/com.name.name E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.name.name, PID: 22020
                                                                             java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                                 at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                 at android.view.View.performClick(View.java:5642)
                                                                                 at android.view.View$PerformClick.run(View.java:22338)
                                                                                 at android.os.Handler.handleCallback(Handler.java:751)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                 at android.os.Looper.loop(Looper.java:154)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6209)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                              Caused by: java.lang.reflect.InvocationTargetException
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                                 at android.view.View.performClick(View.java:5642) 
                                                                                 at android.view.View$PerformClick.run(View.java:22338) 
                                                                                 at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                 at android.os.Looper.loop(Looper.java:154) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6209) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                                                                              Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.name.name/files/Download/OOOO.xlsx exposed beyond app through Intent.getData()
                                                                                 at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
                                                                                 at android.net.Uri.checkFileUriExposed(Uri.java:2346)
                                                                                 at android.content.Intent.prepareToLeaveProcess(Intent.java:8933)
                                                                                 at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
                                                                                 at android.app.Instrumentation.execStartActivity(Instrumentation.java:1690)
                                                                                 at android.app.Activity.startActivityForResult(Activity.java:4290)
                                                                                 at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
                                                                                 at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                                 at android.app.Activity.startActivityForResult(Activity.java:4249)
                                                                                 at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
                                                                                 at android.app.Activity.startActivity(Activity.java:4588)
                                                                                 at android.app.Activity.startActivity(Activity.java:4548)
                                                                                 at com.name.name.MainActivity.OnlyReadFile(MainActivity.java:179)
                                                                                 at com.name.name.MainActivity.onStaff(MainActivity.java:52)
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                                                                                 at android.view.View.performClick(View.java:5642) 
                                                                                 at android.view.View$PerformClick.run(View.java:22338) 
                                                                                 at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                 at android.os.Looper.loop(Looper.java:154) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6209) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
  </code></pre>