我尝试在 Oreo 中打开 PDF 文件,但它没有打开。我没有收到任何错误。问题是什么?PDF 文件打不开。只显示黑屏。在 logcat 中没有错误显示。怎么了?
我该如何解决这个问题?我提到了很多链接,但没有得到解决方案。我也尝试了很多代码,但没有帮助。
我的代码是:
File file11 = new File(Environment.getExternalStorageDirectory().
getAbsolutePath(),
"AtmiyaImages/" + nameoffile1);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if(Build.VERSION.SDK_INT>24){
Uri uri=FileProvider.getUriForFile(AssignmentActivity.this,
getPackageName()+".provider",file11);
target.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
target.putExtra(Intent.EXTRA_STREAM,uri);
target.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
target.setType("application/pdf");
Intent intent=Intent.createChooser(target,"Open File");
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(AssignmentActivity.this,"No Apps
can performs This acttion",Toast.LENGTH_LONG).show();
}
}
else
{
target.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
target.setDataAndType(Uri.fromFile(file11),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent=Intent.createChooser(target,"Open File");
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(AssignmentActivity.this,"No Apps can performs This
acttion",Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
在清单中我还添加
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.infinity.infoway.atmiya.fileprovider" …Run Code Online (Sandbox Code Playgroud) 我从SpannableString设置文本视图数据.它的工作正确.但是当我从另一个活动文本视图中按回按钮时,未在Oreo中显示数据.它在其他版本中正常工作,但在高版本中无效.是什么原因?
这是我的设置数据代码:
tvItinerari=(TextView) view.findViewById(R.id.tv_1);
String text = "";
String name = "";
for (Itinerary item : arrayList) {
text += item.getItinerary()+" ";
}
SpannableString ss = new SpannableString(text);
int start = 0, end;
for (final Itinerary item : arrayList) {
setSpanOnLink(ss, item.getItinerary(), new MyClickableSpan(item));
}
tvItinerari.setText(ss);
Log.e("ss",""+ss);
Run Code Online (Sandbox Code Playgroud)
它适用于奥利奥以外的所有版本.
数据在低版本中正确显示,如棒棒糖,但不适用于高版本.