gpt4 book ai didi

android - 从 Android 图片库中选择图片 - PhoneGap 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 14:51:23 25 4
gpt4 key购买 nike

对于 PhoneGap 2.8.0 中的 Android:

我需要从手机图库中获取图像并需要插入到应用中...

我的代码:

头:

<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="stylesheet" href="css/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="css/styles.css" />

<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.0rc1.min.js"></script>
<script src="js/cordova.js"></script>

HTML:

<button data-theme="d" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">Browse    Photos</button>

<div id="photos"></div>

脚本:

function onPhotoURISuccess(imageURI) {

var img = $('<img />');
img.attr('src', imageURI);


img.appendTo('#photos');

}

但它不起作用....我该怎么做?

控制台报错

file:///android_asser/www/index.html:未捕获类型错误:无法读取未定义的属性“PHOTOLIBRARY”

未捕获的类型错误:[Object Object] 在 file:///android_asset/www/js/jquery.mobile-1.0rc1.min.js 没有方法“split”

在我删除了 jquery 和 jquery-mobile 之后,它的工作...jQuery 与 phonegap 有任何问题吗?

提前致谢

最佳答案

我已经实现了这段代码...最近...检查一下

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

var pictureSource;
var destinationType;

document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady()
{
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}


function onPhotoURISuccess(imageURI)
{
console.log(imageURI);
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}

function onPhotoDataSuccess(imageURI)
{
var imgProfile = document.getElementById('imgProfile');
imgProfile.src = imageURI;
if(sessionStorage.isprofileimage==1)
{
getLocation();
}
movePic(imageURI);
}

function onFail(message)
{
alert('Failed because: ' + message);
}

function movePic(file)
{
window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError);
}

function resolveOnSuccess(entry)
{
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
var myFolderApp = "MyAppFolder";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys)
{
fileSys.root.getDirectory( myFolderApp,
{create:true, exclusive: false},
function(directory)
{
entry.moveTo(directory, newFileName, successMove, resOnError);
},
resOnError);
},
resOnError);
}

function successMove(entry)
{
sessionStorage.setItem('imagepath', entry.fullPath);
}

function resOnError(error)
{
alert(error.code);
}

function capturePhotoEdit()
{
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

function getPhoto(source)
{
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}



</script>

我的 html

<button onclick="capturePhoto();">Capture Photo</button>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Gallery!!</button>

关于android - 从 Android 图片库中选择图片 - PhoneGap 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17228189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com