当用户点击链接时,我需要在inappbrowser中显示pdf.它在ios中工作正常,但没有在android上工作.我正在为我的项目使用IBM worklight.以下是我使用过的代码:
window.open("pdfURL","_blank","location=yes");
Run Code Online (Sandbox Code Playgroud)
在ios中,inappbrowser启动并显示pdf,但在android中,inappbrowser启动但没有显示内容
我是android的新手,我过去两天一直在网上搜索这个.我发现以下链接,但我没有得到如何以及在何处实现此代码以在完全下载后开始自动安装apk文件以及如何在安装后删除下载的apk文件.请指导我正确的方法帮助我.
http://www.anddev.org/viewtopic.php?p=23928
编辑:
我在清单文件中写了这段代码:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<!-- <uses-permission android:name="android.permission.INSTALL_PACKAGES"/> -->
<application android:icon="@drawable/biz_logo"
android:permission="android.permission.WRITE_CONTACTS">
<activity android:name="com.biz.mlm.Main">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud) 我一直在尝试解决从外部存储目录共享图像的问题。它适用于大多数设备,但不适用于其他设备。\n我有:\n1。添加了一个扩展 FileProvider 的类:
\n\npublic class GenericFileProvider extends FileProvider {}\nRun Code Online (Sandbox Code Playgroud)\n\npublic class GenericFileProvider extends FileProvider {}\nRun Code Online (Sandbox Code Playgroud)\r\n <provider\r\n android:name=".Utils.GenericFileProvider"\r\n android:authorities="${applicationId}.provider"\r\n android:exported="false"\r\n android:grantUriPermissions="true">\r\n <meta-data\r\n android:name="android.support.FILE_PROVIDER_PATHS"\r\n android:resource="@xml/provider_paths"/>\r\n </provider>Run Code Online (Sandbox Code Playgroud)\r\n我的共享图像功能如下:
\n\n private fun shareInEmail() {\n val filename = "Avoir+$timeStamp.jpg"\n val filelocation = File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename)\n val path : Uri = FileProvider.getUriForFile(\n requireContext(),\n context!!.applicationContext.packageName.toString() + ".provider",\n filelocation\n )\n\n context!!.grantUriPermission(\n …Run Code Online (Sandbox Code Playgroud) 我不知道你是否看过惊人的Mytrack更新,但它允许将一个kml文件发送到Google Earth应用程序并将其显示在Google应用程序中(当然,如果已安装).

源代码在那里:http://code.google.com/p/mytracks/source/browse/
但我无法找到实现这一目标的方法.
我想我在这里找到了一些内容:http://code.google.com/r/jshih-mytracks3/source/browse/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java?specl = svn5178eb75934b7f0c4c23ec26b7d79a0787de18b8&R = 5178eb75934b7f0c4c23ec26b7d79a0787de18b8
else if (playTrack) {
Intent intent = new Intent()
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
.setClassName(GOOGLE_EARTH_PACKAGE, GOOGLE_EARTH_CLASS)
.setDataAndType(Uri.fromFile(new File(savedPath)), GOOGLE_EARTH_KML_MIME_TYPE);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
硬编码方式提供此代码:
Intent intent = new Intent()
.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("com.google.earth.EXTRA.tour_feature_id","tour")
.setClassName("com.google.earth", "com.google.earth.EarthActivity")
.setDataAndType(Uri.fromFile(new File("/sdcard/test.kml")),
"application/vnd.google-earth.kml+xml");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是上面的代码只显示了与此代码相同结果的路径:
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
Uri uri1 = Uri.parse("file:///sdcard/test.kml");
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent, "Sample"));
Run Code Online (Sandbox Code Playgroud)
我的目标是通过"播放"按钮获得相同的结果.
我正在将资产中的HTML文件加载到webview中.
html包含指向其他html资源文件的链接.单击链接可在SDK <24上正常工作,但FileUriExposedException在单击Nougat(SDK 24)设备上第二个html页面的链接时会产生错误.
将资产中的html加载到webview中的代码:
wbHelp.loadDataWithBaseURL("file:///android_asset/", readAssetFileAsString("Index.html"), "text/html", "UTF-8", null);
Run Code Online (Sandbox Code Playgroud)
和readAssetFileAsString是:
private String readAssetFileAsString(String sourceHtmlLocation)
{
InputStream is;
try
{
is = getContext().getAssets().open(sourceHtmlLocation);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
return new String(buffer, "UTF-8");
}
catch(IOException e)
{
e.printStackTrace();
}
return "";
}
Run Code Online (Sandbox Code Playgroud)
HTML可以是非常基本的.的index.html
<html><a href="Page2.html">Page 2</a></html>
Run Code Online (Sandbox Code Playgroud)
Page2.html
<html><h1>Page 2</h1>
Run Code Online (Sandbox Code Playgroud)
完整的错误日志是:
11-12 17:58:03.694 5831-5831/appname W/System.err: android.os.FileUriExposedException: file:///android_asset/Page2.html exposed beyond app through Intent.getData()
11-12 17:58:03.694 5831-5831/appname W/System.err: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
11-12 17:58:03.694 5831-5831/appname W/System.err: at android.net.Uri.checkFileUriExposed(Uri.java:2346) …Run Code Online (Sandbox Code Playgroud)在 androidx.activity 版本 1.2.0-alpha05 中,TakePicture 合约的 API 已更改:
TakePicture 合约现在返回一个指示成功的布尔值而不是缩略图位图,因为在将图像写入提供的 Uri 时,相机应用程序很少支持这一点
虽然在 alpha04 回调中接收到一个 Bitmap 对象,但现在回调只接收一个描述成功的布尔对象。
所以现在launcher的launch方法的Uri Parameter一定不能为null,而必须是图片保存的目的地。没有设法创建一个被启动器接受的 Uri 对象,该对象可用于我的应用程序读取结果图片。
有没有人为我提供可以提供给启动器的有效 Uri 对象的示例?
我正在拍摄如下照片:
activity.startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), BaseDef.REQUEST_CODE_CAMERA);
Run Code Online (Sandbox Code Playgroud)
之后,我只想获取新的图像路径、uri 或类似的(不是位图或图像数据),以便我知道新图像的位置。因此,我尝试检索 uri,如下所示:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == BaseDef.REQUEST_CODE_CAMERA)
{
if (resultCode == RESULT_OK)
{
Uri uri = data.getData();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但 uri 有时是null. 如何在此类设备上获取图像路径/uri?
编辑
我真的想保留使用任何相机应用程序创建的默认文件名!
当前的解决方法(我不知道这是否总是有效):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == BaseDef.REQUEST_CODE_CAMERA)
{
if (resultCode == RESULT_OK)
{
String path = null;
Uri uri = data.getData();
if (uri != null)
path = MediaUtil.getRealPathFromURI(uri);
else
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用FileProvider在Android Nougat上拍照,这是我的代码
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mypackage.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
file_paths.xml:
<paths>
<files-path name="img" path="images/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
Java的:
String fileName = "cameraOutput" + System.currentTimeMillis() + ".jpg";
File imagePath = new File(getContext().getFilesDir(), "images");
File file = new File(imagePath, fileName);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final Uri outputUri = FileProvider.getUriForFile(activity, "com.mypackage.fileprovider", file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
getContext().grantUriPermission(
"com.google.android.GoogleCamera",
outputUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION
);
cameraIntent.setFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
activity.startActivityForResult(cameraIntent, ACTIVITY_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
相机活动开始,成功拍照,但活动结果不正常,我在错误日志中看到的唯一的事情是
CAM_StateSavePic:将结果保存到URI时发生异常:Optional.of(content://com.mypackage.fileprovider/img/cameraOutput1469383289530.jpg)FileNotFoundException:是一个目录
编辑 错过了File#createNewFile();
我想要的只是在我的外部下载目录中打开一个 pdf 文件。
我使用这段代码打开该文件,并且它曾经工作正常。
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
+ File.separator + filename);
Uri path = Uri.fromFile(file);
Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
pdfOpenintent.setDataAndType(path, "application/" + getExtension(filename));
pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
CourseModulesActivity.this.startActivity(pdfOpenintent);
} catch (ActivityNotFoundException e) {
pdfOpenintent.setType("application/*");
startActivity(Intent.createChooser(pdfOpenintent, "No Application found to open File - " + filename));
}
Run Code Online (Sandbox Code Playgroud)
现在在 android N(API 24+) 中,它崩溃了android.os.FileUriExposedException
我按照链接 - /sf/answers/2720062831/和https://developer.android.com/training/secure-file-sharing/share-file.html#ShareFile将我的代码转换为此-
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
+ File.separator + filename);
Uri path = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
Intent pdfOpenintent = …Run Code Online (Sandbox Code Playgroud) 我试图通过摆脱FileUriExposedException来支持Nougat.当我使用Uri.fromFile(gettheImageFilehere())方法我成功获取图像路径文件:///storage/emulated/0/DCIM/Camera/IMG_20170308_171951.jpg
当我使用
FileProvider.getUriForFile(HomeView.this, getApplicationContext().getPackageName() + ".provider",
gettheImageFilehere());
Run Code Online (Sandbox Code Playgroud)
我得到的图像路径为:/external_files/DCIM/Camera/IMG_20170308_171951.jpg
我试图使用android.os.FileUriExposedException上提供的实现. 这是我在androidmanifest.xml 里面的代码,我添加了提供程序:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
Run Code Online (Sandbox Code Playgroud)
然后我在res/xml文件夹中创建了provider_paths.xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Run Code Online (Sandbox Code Playgroud)
我对上述情况表示怀疑:
我得到的完整错误是无法解码流:java.io.FileNotFoundException:/ external_files/DCIM/Camera/IMG_20170308_175833.jpg(没有这样的文件或目录)
代码段的.java文件是在这里查看我的实现.
android ×9
androidx ×1
camera ×1
cordova ×1
download ×1
google-earth ×1
image ×1
installation ×1
javascript ×1
jquery ×1
kml ×1
uri ×1
webview ×1