我試圖讓用戶在我的應(yīng)用程序中導(dǎo)出一個(gè) excel 文件,并讓該應(yīng)用程序自動(dòng)打開(kāi)創(chuàng)建的 excel 文件。使用 jxl 成功創(chuàng)建并存儲(chǔ)了 excel 文件,但是當(dāng)我嘗試使用 Hancom Office 編輯器打開(kāi)它時(shí),除了屏幕出現(xiàn)黑色覆蓋之外,什么也沒(méi)有發(fā)生。這是一個(gè) gif: 我無(wú)法弄清楚是什么導(dǎo)致了這種情況,也無(wú)法在網(wǎng)上找到任何相關(guān)信息。我正在使用這里接受的答案來(lái)支持我的目標(biāo) SDK 28。我的導(dǎo)出方法: 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 標(biāo)記(設(shè)置為的子項(xiàng)):<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>據(jù)我所知,我沒(méi)有收到任何錯(cuò)誤或警告。謝謝你的幫助。
無(wú)法使用 Intent.ACTION_VIEW 在 Android 上打開(kāi) Excel 文件
人到中年有點(diǎn)甜
2021-06-18 15:03:15