- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的数据库中有一个 .mhtml 文件作为字节数组。我写了下面的代码,它在 Lollipop 之前的设备上运行良好。但它不适用于 Lollipop 和棉花糖。
代码:-
String path = filepath.getAbsolutePath()+"/StudyWellAppv5/"+fname;
byte[] bytes = tblK.gethtmlFile();
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
webview.loadUrl("file://" + path);
}
catch(Exception e){ e.printStackTrace();}
运行时权限代码:-
/Permission to read and write from external storage
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
int permission = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
int readpermission = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED||readpermission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
getActivity(),
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
错误日志:-
"Blocked script execution in 'file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (1618)
06-16 13:48:42.571 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(1618)] "Blocked script execution in 'file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (1618)
06-16 13:48:42.598 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///C:/EC2C4CD1/1_files/image002.jpg", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (0)
06-16 13:48:42.599 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///C:/EC2C4CD1/1_files/image004.jpg", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (0)
06-16 13:48:42.599 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///C:/EC2C4CD1/1_files/image006.jpg", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (0)
06-16 13:48:42.671 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///C:/EC2C4CD1/1_files/image008.jpg", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (0)
06-16 13:49:10.182 1244-1244/com.samji.StudyWellAppv5 I/chromium: [INFO:CONSOLE(0)] "Not allowed to load local resource: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml", source: file:///storage/emulated/0/StudyWellApp/2016-06-16%2001-48-42.mhtml (0)
注意:- 此代码在 Lollipop 之前的设备上运行完美。它不仅仅适用于 Lollipop 和棉花糖。
最佳答案
您必须获得 API 23(棉花糖)的运行时许可
示例代码:
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_RUNTIME_PERMISSION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//SomeStuffWhichNeedPermission(); dont call here directly wihtout permission in 6.0 do like below
checkPremission();
}
void SomeStuffWhichNeedPermission() {
// storing data code here now
String path = filepath.getAbsolutePath() + "/StudyWellAppv5/" + fname;
byte[] bytes = tblK.gethtmlFile();
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
webview.loadUrl("file://" + path);
} catch (Exception e) {
e.printStackTrace();
}
}
void checkPremission() {
//select which permission you want
final String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
// if in fragment use getActivity()
if (ContextCompat.checkSelfPermission(ActivityName.this, permission)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(ActivityName.this, permission)) {
} else {
ActivityCompat.requestPermissions(ActivityName.this, new String[]{permission}, REQUEST_CAMERA_PERMISSION);
}
} else {
// you have permission go ahead
SomeStuffWhichNeedPermission();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_RUNTIME_PERMISSION:
final int numOfRequest = grantResults.length;
final boolean isGranted = numOfRequest == 1
&& PackageManager.PERMISSION_GRANTED == grantResults[numOfRequest - 1];
if (isGranted) {
// you have permission go ahead
SomeStuffWhichNeedPermission();
} else {
// you dont have permission show toast
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
关于android - mhtml 文件无法在 Lollipop 和棉花糖的 webview 中正确加载/显示,但在 Lollipop 之前的设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854319/
我使用工具栏是为了在我的应用程序中进行 Material 设计。一切正常,但除了更改菜单项文本颜色时,我完全无法接受该解决方案。我还张贴了我在申请中使用的文本和代码的屏幕截图,供您引用。我尝试了几种替
看起来 FloatingActionButton 在 Android 4.0 和 Lollipop 上无法正常工作。正如您在下图中看到的那样,在 Android Lollipo 上,阴影缺失,而在 A
SDK 升级到 Android 5 后,我无法使用 Intel 硬件加速执行管理器: $ android-sdk-macosx/tools/emulator -avd AVD_for_LowMemor
SDK升级到Android 5后,无法使用Intel Hardware Accelerated Execution Manager: $ android-sdk-macosx/tools/emulat
我有不同 draw9patch png 作为背景的按钮。目前按钮由 selector 控制,看起来像这样: 对于 Android Lollipop,他们有一个用于触摸效果的
我尝试在 Pre-Lollipop 设备上运行我的应用程序。但是这段代码向我显示了 Pre-Lolliop 和 Lollipop 设备的相同错误。 如果我将“android:”添加到样式中(如样式 2
我实现了一个自定义的 SurfaceView 来绘制相机预览,并在其上完成了所有捕获和手动对焦操作。它在 Pre-Lolipop 设备上运行良好,但问题是它在 Lollipop 设备上崩溃。 发生的最
风格 @color/my_primary_color @color/my_primary_dark_color @color/accent 布局
我想在 Lollipop 设备中显示较旧的时间选择器(如 Lollipop 设备之前的时间选择器)。可以 这是可能的。 最佳答案 您可以通过将 timePickerMode 属性设置为“spinner
嗨,所以我有点困惑,想知道是否有人能指出我正确的方向。 在 Lollipop 和 pre-lollipop 上使用 Google Play 商店 您会在 Lollipop 上看到可选择的 View 具
如果我们希望使用 Material Design 的应用同时支持 Lollipop 和 Lollipop 之前的设备,以下哪种方法是正确的? 单独使用 Android 支持库:仅对整个应用程序使用支持
我正在使用 appcompat/support-v7 中引入的新工具栏小部件。我想根据用户是否向上/向下滚动页面来隐藏/显示工具栏,就像在新的 Google Playstore 应用程序或 NewsS
我的数据库中有一个 .mhtml 文件作为字节数组。我写了下面的代码,它在 Lollipop 之前的设备上运行良好。但它不适用于 Lollipop 和棉花糖。 代码:- String p
根据标题,我能够在下面的 Lollipop 中成功读取/写入数据,但在 Lollipop 中多次读取/写入失败。 这就是我读/写数据的方式: boolean isRead= getmBluetooth
我刚刚在 Android Studio 上安装了 Android 5,并在模拟器上进行了第一次运行。我发现“API Demos”应用程序非常有趣,我想找到代码。我说的是这个应用程序: 有人知道我在哪里
我正在关注 this tutorial在 Android Material Design 中使用颜色(我的 ActionBar 和 StatusBar)。我确实按照教程进行操作,但没有反射(refle
在我的应用程序中,用户可以通过它调用任何号码,我正在启动蓝牙 audioManager.setBluetoothScoOn(true); audioManager.startBluetoothSco(
我正在我的 android 应用程序中实现 Google map API v2。该应用程序在所有设备上都可以正常工作,但在 Lollipop 设备上却不行。应用程序在 Lollipop 中崩溃。我确实
我正在开发一个项目,其中有一个日期选择器。我正在尝试为其设置最大日期和最短日期。最短日期是今天之后 1 天,最大日期是今天之后 11 天。但问题是在 Lollipop 设备中,最后一个最大日期显示为可
我正在使用嵌入式无线系统,它以定义的时间间隔生成数据包。目的是检测设备/系统何时重新启动。为此,我读到 Lollipop 序列编号是最适合此目的的编号方案。 “在此编号方案中,序列号从负值开始,增加直
我是一名优秀的程序员,十分优秀!