简体   繁体   English

Phonegap相机拍照

[英]Phonegap camera take a picture

I'm working on adding some mobile app specific functionality to my mobile website. 我正在努力为我的移动网站添加一些移动应用程序特定的功能。 Currently, the app is more or less just a wrapper. 目前,该应用程序或多或少只是一个包装器。

public class Activity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        if (this.isOnline()) {
            super.loadUrl("http://mysite.com");
        } else {
            super.loadUrl("file:///android_asset/www/offline.html");
        }
    }

    public boolean isOnline() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }
}

The problem rises with the following javascript. 问题随着以下javascript而上升。 If I replace super.loadUrl("http://mysite.com"); 如果我替换super.loadUrl(“http://mysite.com”); with super.loadUrl("file:///android_asset/www/online.html") and run the following javascript there, it works fine. 使用super.loadUrl(“file:///android_asset/www/online.html”)并在那里运行以下javascript,它工作正常。 But if I run it on mysite.com, it keeps on throwing the following exception: 但如果我在mysite.com上运行它,它会继续抛出以下异常:

07-13 12:25:12.762: E/Web Console(28251): Not allowed to load local resource: file:///data/data/com.my.app/.Pic.jpg?1342171460960 at null:0 07-13 12:25:12.762:E / Web控制台(28251):不允许加载本地资源:file:///data/data/com.my.app/.Pic.jpg?1342171460960 at null:0

Any thoughts on what I'm doing wrong? 对我做错了什么的想法?

 var camera = (function(){

        var camera = {
            settings : {
                quality: 50, 
            }
        };

        var error = function(message) {
            console.error("Error happened while trying to get a picture", message);
        };

        document.addEventListener("deviceready", function() {

            camera.settings.destinationType = navigator.camera.DestinationType.FILE_URI;    

            camera.fromPhone = function() {
                this.settings.sourceType = navigator.camera.PictureSourceType.CAMERA;
                return this;
            };

            camera.fromLibrary = function() {
                this.settings.sourceType = navigator.camera.PictureSourceType.PHOTOLIBRARY;
                return this;
            };

            camera.get  = function(callback) {
                navigator.camera.getPicture(callback, error, camera.settings);
            };

        }, false);


        return camera;

 })();

//Later, at a click event
camera.fromPhone().get(function(imageURI){
    alert("imageURI" + imageURI)
    $("#largeImage").attr("src", imageURI);
});

Your remotely loaded site can not access the local resources due to browser cross domain security. 由于浏览器跨域安全性,您的远程加载站点无法访问本地资源。 This is an old thread but explains some reasons for it. 这是一个旧线程,但解释了它的一些原因。

https://lists.webkit.org/pipermail/webkit-dev/2009-May/007658.html https://lists.webkit.org/pipermail/webkit-dev/2009-May/007658.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM