当我通过App PhoneGap运行应用程序的代码时,我的应用程序将运行。 但是,如果代码将其转换为apk并将其安装在我的android手机上,则启动相机并将照片上传到服务器的按钮将不起作用。 我带给你代码:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />
<title>My app</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Script -->
<script type="text/javascript" src="cordova.js" ></script>
<script type='text/javascript' src='jquery-3.0.0.js' ></script>
</head>
<body>
<div align="center" id="logo"><img src="img/logo.png" width="50%"></div>
<div style="margin:0 auto; width:30%!important;text-align: center;">
<img src="img/cam3.jpg" id='img' style="width: 100px; height: 100px;">
</div><br/>
<div style="width:100%; text-align:center; padding:10px;">
<div class="text-center mt-4">
<button id='but_take' type="button" class="btn btn-primary" >Cattura reperto</button>
</div>
<div style="margin-top: 30px; " class="text-center mt-4">
<a type="button" class="btn btn-info" href="#" onclick="window.open('https://myserverexample.com/img.php', '_system');">Guarda reperti</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
// take picture from camera
$('#but_take').click(function(){
navigator.camera.getPicture(onSuccess, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URL
});
});
// Change image source and upload photo to server
function onSuccess(imageURI) {
// Set image source
var image = document.getElementById('img');
image.src = imageURI + '?' + Math.random();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
// load image to server
var ft = new FileTransfer();
ft.upload(imageURI, "http://myserverexample.com/load-image.php", function(result){
alert('image load ' );
}, function(error){
alert('error : ' + JSON.stringify(error));
}, options);
}
function onFail(message) {
alert('No Image: ' + message);
}
});
</script>
</body>
</html>
我应该怎么做才能使代码在android上工作?有什么办法可以查看android上apk手机差距的错误吗?谢谢