我试图让用户在我的应用程序中导出一个 excel 文件,并让该应用程序自动打开创建的 excel 文件。使用 jxl 成功创建并存储了 excel 文件,但是当我尝试使用 Hancom Office 编辑器打开它时,除了屏幕出现黑色覆盖之外,什么也没有发生。这是一个 gif: 我无法弄清楚是什么导致了这种情况,也无法在网上找到任何相关信息。我正在使用这里接受的答案来支持我的目标 SDK 28。我的导出方法: public void onExport(View view){ try { //write changes to excel file(changes made outide of function) workbook.write(); workbook.close(); Toast.makeText(getApplication(), "Data Exported to Excel Sheet", Toast.LENGTH_SHORT).show(); findViewById(R.id.btn_export).setEnabled(false); //set file to saved excel file File file = new File(Environment.getExternalStorageDirectory(), race.getName()+".xls"); Uri path = FileProvider.getUriForFile(getApplicationContext(), "com.something.racecalculator.fileprovider", file); Intent intent = new Intent(Intent.ACTION_VIEW); Log.i("path: ", path.toString()); intent.setDataAndType(path, "image/jpg"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } catch (IOException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } catch (ActivityNotFoundException e) { Log.i("oh no:", "No application available to view excel"); } }我在 AndroidManifest.xml 中的 provider 标记(设置为的子项):<provider android:name=".GenericFileProvider" android:authorities="com.something.racecalculator.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>据我所知,我没有收到任何错误或警告。谢谢你的帮助。
添加回答
举报
0/150
提交
取消