简体   繁体   English

如何使用phonegap从HTML页面导航到本机屏幕?

[英]How to navigate from HTML page to native screen using phonegap?

i have made Hello world test app for Android and iOS using PhoneGap Framework. 我使用PhoneGap Framework为Android和iOS制作了Hello world测试应用程序

I want to invoke Native Screens from the HTML page. 我想从HTML页面调用Native Screens。

How can i invoke native screen from HTML page? 如何从HTML页面调用本机屏幕?

And vice versa. 反之亦然。

You can't open any Native Screen directly.If you want to use native API of the devices means if you want to open native screen then there are several APIs available in PhoneGap.Using this APIs you can implement native functionalities into your application with HTML,CSS and Javascript. 您无法直接打开任何本机屏幕。如果您想使用设备的本机API,则意味着如果您要打开本机屏幕,那么PhoneGap中有几个可用的API。使用此API,您可以使用HTML在应用程序中实现本机功能,CSS和Javascript。

Here is the link for that APIs: PhoneGap API 以下是该API的链接: PhoneGap API

This is one sample code.This will open device's Photo Gallery and shows chosen image in your HTML Page. 这是一个示例代码。这将打开设备的照片库并在HTML页面中显示所选图像。

<!DOCTYPE html>
<html>
  <head>
    <title>Capture Photo</title>

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

    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 

    // Wait for Cordova to connect with the device
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // Cordova is ready to be used!
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageData) {
      // Uncomment to view the base64 encoded image data
      // console.log(imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI 
      // console.log(imageURI);

      // Get image handle
      //
      var largeImage = document.getElementById('largeImage');

      // Unhide image elements
      //
      largeImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      largeImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    // 
    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>
  </head>
  <body>
    <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="" />
    <img style="display:none;" id="largeImage" src="" />
  </body>
</html>

Hope this will Help. 希望这会有所帮助。

Note: 注意:

You won't be able to open any screen directly into your app using HTML.You have to go through the phonegap API if you are developing an application using PhoneGap. 您将无法使用HTML直接打开任何屏幕。如果您正在使用PhoneGap开发应用程序,则必须通过phonegap API。

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

相关问题 如何在我的phonegap应用程序中从网页导航到本地页面? - How to navigate from a webpage to local page in my phonegap app? 如何使用react导航在react native中从登录页面导航到主页? - How to navigate from Login Page to Home Page in react native using react navigation? 如何在 React Native 中从一个屏幕导航到另一个屏幕? - How to navigate from one screen to another in React native? 如何在phonegap应用程序中将html页面设置为跨整个屏幕? - How to set html page in phonegap app to be across whole screen? 如何使用React Native导航页面 - How to navigate page with React Native React Native:如何导航到页面? - React Native: How to navigate to a page? 如何使用Android中的phonegap将数据(移动联系人数组)从一个HTML页面传输到另一HTML? - how to transfer data(array of mobile contacts) from one html page to other html using phonegap in android? 如何使用Phonegap中的JavaScript将数据从一个html传递到另一个html页面? - How to pass the data from one html to another html page using JavaScript in Phonegap? 如何导航到 react-native 中的嵌套屏幕 - How to navigate to nested screen in react-native 如何在 React Native 上的屏幕之间导航? - How to navigate between screen on React Native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM