0

I am building a Hybrid Android app using HTML5, JavaScript and IDE(eclipse).

In my app, I made two html page. One is index.html and the other one is camera.html.

[index.html]

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
 <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
 <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
</head>
 
<body>
 <div data-role="page" id="index" style="width:100%; height:100%">
     <div data-role="header">
      <h1 class="title">Read Database</h1>
     </div>
     <div data-role="content">
       <ul data-role="listview" data-inset="true" id="result"></ul>
     </div>
     <div data-role="footer">
         <a href="insert.html" data-role="button" >Insert Data</a>
         <a href="camera.html" data-role="button" >Camera/a>
  </div>
 </div>
</body>
</html>

[camera.html]

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
 <meta name="viewport" content="width=device-width, initial-scale=1" />
 <script>
     var pictureSource;  
  var destinationType;  
  document.addEventListener("deviceready",onDeviceReady,false);
  
  function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
  }
  function onPhotoDataSuccess(imageData) {
    var smallImage = document.getElementById('smallImage');
    smallImage.style.display = 'block';
    smallImage.src = "data:image/jpeg;base64," + imageData;
  }
  function onPhotoURISuccess(imageURI) {
    var largeImage = document.getElementById('largeImage');
    largeImage.style.display = 'block';
    largeImage.src = imageURI;
  }
  function capturePhoto() {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
      correctOrientation : true,
      destinationType: destinationType.DATA_URL });
  }
  function capturePhotoEdit() {
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, 
      allowEdit: true, //android에서는 특별한 효과 없음, 무시됨
      correctOrientation : true,
      destinationType: destinationType.DATA_URL });
  }
  function getPhoto(source) {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
      correctOrientation : true, 
      destinationType: destinationType.FILE_URI,
      sourceType: source });
  }
  function onFail(message) {
    alert('Failed because: ' + message);
  }
 </script>
</head>
 
<body>
 <div data-role="page" id="camera" style="width:100%; height:100%">
     <div data-role="header">
      <h1 class="title">Camera</h1>
     </div>
     <div data-role="content">  
      <img style="display:none; wdith:100%; height:100%" id="largeImage" src=""/>
  </div>
     <div data-role="footer">         
       <a href="index.html" data-role="button" >Main</a>
         <button onclick="capturePhoto();">Capture Photo</button> <br>
      <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
      <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
      <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
      <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
  </div>
 </div>
</body>
</html>

If it sees in these codes, I connected index.html to camera.html using A tag button.

When I pressed and moved this button, JavaScript is not worked.

When moving from index.html page to the other page, Other than the JavaScript codes in index.html, It doesn't work.

enter image description here

this picture is result that i pressed a button in hybrid app.

how can i solve this problem?

[Updated] [MainActivity.java]

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package app.su.project;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}
eastglow
  • 219
  • 3
  • 18
  • Can you include your Main_Activity.java file? – zehata Aug 22 '16 at 03:03
  • Are you going to use the javascript code inside `index.js` in `camera.html`? If you are, you should add `` inside `camera.html` – dariru Aug 22 '16 at 03:12
  • you probably havent enabled Javascript in the webview settings -- webview.getSettings().setJavaScriptEnabled(true); – Tasos Aug 22 '16 at 03:51
  • @zehata i added MainActivity.java sources. – eastglow Aug 22 '16 at 04:03
  • @Dar index.js include just selected data codes. index.js have nothing to do with camera.html. – eastglow Aug 22 '16 at 04:06
  • @ArtNouveau What does this mean: "When moving from index.html page to the other page, Other than the JavaScript codes in index.html, It doesn't work." – dariru Aug 22 '16 at 04:24
  • @Tasos It feels sorry but how can i edit webview settings? – eastglow Aug 22 '16 at 04:26
  • @Dar when i clicked the button(move to camera.html), JS sources in camera.html doesn't work. But JS sources of index.html(Main Page in hybrid App) do work. Do you understand? (I can't english very well. sorry) – eastglow Aug 22 '16 at 04:28
  • @ArtNouveau have you tried adding `` in `camera.html` as well? – dariru Aug 22 '16 at 04:54
  • @Dar I tried adding cordova.js source but it doesn't work...u_u – eastglow Aug 22 '16 at 05:06
  • @ArtNouveau Please refer to this page in order to navigate to another HTML page: http://stackoverflow.com/questions/12280351/how-to-navigate-one-page-to-another-page-in-android-phonegap – dariru Aug 22 '16 at 05:47
  • You are using Cordova so JS is enabled by default as cordova uses Javascript to initialize the App. Maybe things arent running because of the whitelist https://github.com/apache/cordova-plugin-whitelist – Tasos Aug 22 '16 at 06:43
  • @Dar Thanks for your help. Unfortunately, It doesn't go well... – eastglow Aug 22 '16 at 07:57
  • @Tasos Whitelist is one of kind security policy that i know. Then, does that have to be deleted? – eastglow Aug 22 '16 at 08:02
  • The whitelist is there so can you amend parts of it to secure your APP. What i suggest is to remote debug your APP https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging?hl=en -- http://geeklearning.io/apache-cordova-and-remote-debugging-on-android/ – Tasos Aug 22 '16 at 13:18

0 Answers0