标签: phonegap-plugins

Phonegap - 如何从base64字符串生成图像文件?

我正在为Android编写一个phonegap应用程序,我将base64 PNG字符串保存为文件.但是,我发现字符串只是转储到文件中,打开时无法将其视为图像.

我希望能够保存从base64字符串生成的图像.这就是我所拥有的:

Javascript(Formated for Phonegap):

/*** Saving The Pic ***/
var dataURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; //A simple red dot

function gotFS(fileSystem) {
    fileSystem.root.getFile("dot.png", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {  
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    writer.write(dataURL); //does not open as image
}

function fail(error) {
    console.log(error.code);
}
Run Code Online (Sandbox Code Playgroud)

我尝试编辑代码只保存图像数据,但它也没有用.(见下文)

function gotFileWriter(writer) {
     var justTheData = dataURL.replace(/^data:image\/(png|jpg);base64,/, "");//Removes everything up to ...'base64,'
     writer.write(justTheData); //also does not show
 }
Run Code Online (Sandbox Code Playgroud)

触发everthing的HTML:

<p onclick="window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail)">Save a Dot</p>
Run Code Online (Sandbox Code Playgroud)

请帮忙.谢谢.

javascript base64 android phonegap-plugins cordova

6
推荐指数
1
解决办法
1万
查看次数

嵌入Cordova WebView,Receiver未注册

我已将Cordova WebvView作为组件嵌入到我的项目中,除了一件事,一切正常; 当按下后退按钮时,我在LogCat上收到错误消息"接收器未注册!" 我不认为我已经注册了接收器.还有在GitHub上的示例项目在这里.运行此应用程序时,我也得到相同的错误.

我想要做的是,将Cordova WebView嵌入到我的Android项目中并运行一些javascript函数.

这是我的主要活动;

public class MainNativeViewController extends FragmentActivity implements CordovaInterface,
    JavaScriptListener {

FragmentTransaction transaction;
RelativeLayout childBrowser;
RelativeLayout dialogBox;
RelativeLayout emailComposer;

private ExecutorService threadPool;

CordovaWebViewFragment cordovaWebViewFragment;

public CordovaWebView cordovaWebView;

public LayoutInflater inflater;
CordovaPlugin mActivityResultCallback;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_container);

    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    threadPool = Executors.newCachedThreadPool();

    cordovaWebView = SingleTonCordovaWebView.getCordovaWebView(this);
    cordovaWebView.loadUrl("file:///android_asset/www/invoke_native_view.html");

    FragmentManager manager = getSupportFragmentManager();

    ListFragment listFragment = new ListFragment();

    manager.beginTransaction().add(R.id.fragment_container, listFragment).commit();
}

@Override
public void showFragment(String fragmentName) {

    /* …
Run Code Online (Sandbox Code Playgroud)

android phonegap-plugins cordova android-fragmentactivity

6
推荐指数
1
解决办法
6861
查看次数

使用phonegap检查设备的互联网连接

尝试使用cordova 2.0.0并使用此代码检查互联网连接

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

function onDeviceReady() {
    alert("ready");
    db = window.openDatabase("loginintro", "1.0", "loginintro", 1000000);
    db.transaction(populateDB, errorCB, successCB);
    checkConnection();
}
function checkConnection()
{   alert("connection");
    network = navigator.network.connection.type;
    alert("fdfd");
    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';
    alert('Connection type: ' + states[networkState]);
}
Run Code Online (Sandbox Code Playgroud)

但在这条线上得到错误

network = navigator.network.connection.type;
Run Code Online (Sandbox Code Playgroud)

和错误是:

04-09 15:20:23.989: E/Web Console(13329): Uncaught …
Run Code Online (Sandbox Code Playgroud)

phonegap-plugins cordova cordova-2.0.0

6
推荐指数
1
解决办法
2万
查看次数

phonegap插件无法正常工作 - 连接未定义

根据手机间隙文档我应该能够通过简单地添加<gap:plugin name="org.apache.cordova.network-information" />到添加网络cocnnection插件config.xml

我正在使用示例js函数来测试连接,它似乎不起作用.LogCat显示'无法读取属性'类型'未定义',这让我觉得插件从未添加过.

function checkConnection() {
var networkState = navigator.connection.type;

var states = {};
states[Connection.UNKNOWN]  = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI]     = 'WiFi connection';
states[Connection.CELL_2G]  = 'Cell 2G connection';
states[Connection.CELL_3G]  = 'Cell 3G connection';
states[Connection.CELL_4G]  = 'Cell 4G connection';
states[Connection.CELL]     = 'Cell generic connection';
states[Connection.NONE]     = 'No network connection';

alert('Connection type: ' + states[networkState]);
Run Code Online (Sandbox Code Playgroud)

}

config.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
    xmlns:gap   = "http://phonegap.com/ns/1.0"
    id …
Run Code Online (Sandbox Code Playgroud)

javascript phonegap-plugins cordova

6
推荐指数
1
解决办法
4621
查看次数

PhoneGap:如何在InAppBrowser中打开iframe的链接

我使用谷歌dfp在我的PhoneGap项目中投放广告,这些广告呈现为iframe.

当用户点击广告时,我希望在网址中打开该网址InAppBrowser.截至目前,它只是打开了网址WebView.

iframe中的锚标签有target="_blank",但我相信因为它在iframe中,PhoneGap忽略了这一点.

我知道我InAppBrowser正在为我项目中的其他链接工作,所以我已经排除了这一点.

以下是我的config.xml中的一些设置:

...

<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>
<feature name="InAppBrowser">
    <param name="android-package" value="org.apache.cordova.InAppBrowser" />
</feature>

...

<preference name="stay-in-webview" value="false" />

...

<access origin="*" />
Run Code Online (Sandbox Code Playgroud)

这就是呈现的iframe的样子:

<div class="adunit display-block" data-adunit="example_app_section_front_footer" data-dimensions="320x50" id="example_app_section_front_footer-auto-gen-id-1">
    <div id="google_ads_iframe_/2444258/example_app_section_front_footer_0__container__" style="border: 0pt none;">
        <iframe id="google_ads_iframe_/2444258/example_app_section_front_footer_0" name="google_ads_iframe_/2444258/example_app_section_front_footer_0" width="320" height="50" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" src="someurl"  style="border: 0px; vertical-align: bottom;">
            <html>
                <body>
                    <div id="google_image_div">
                        <a id="aw0" target="_blank" href="http://googleads.g.doubleclick.net/aclk?someurl" onfocus="ss('aw0')" onmousedown="st('aw0')" onmouseover="ss('aw0')" onclick="ha('aw0')"><img src="http://pagead2.googlesyndication.com/simgad/000111222" border="0" width="320" height="50" alt="" …
Run Code Online (Sandbox Code Playgroud)

jquery android ios phonegap-plugins cordova

6
推荐指数
1
解决办法
2625
查看次数

自定义配置后,Cordova无法为Android构建

我按照这个说明为我的Cordova/Ionic项目设置了Facebook SDK:http: //ngcordova.com/docs/plugins/facebook/

对于iOS,一切运作良好,但对于Android,最后一步

cordova构建android

失败并出现奇怪的错误:

    -compile:
    [javac] Compiling 97 source files to /Users/glfx/Projects/Sportcial/platforms/android/CordovaLib/ant-build/classes
    [javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
    [javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
    [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
    [javac] /Users/glfx/Projects/Sportcial/platforms/android/CordovaLib/src/org/apache/cordova/CordovaWebViewClient.java:35: error: cannot find symbol
    [javac] import android.webkit.ClientCertRequest;
    [javac]                      ^
    [javac]   symbol:   class ClientCertRequest
    [javac]   location: package android.webkit
    [javac] /Users/glfx/Projects/Sportcial/platforms/android/CordovaLib/src/org/apache/cordova/CordovaWebViewClient.java:145: …
Run Code Online (Sandbox Code Playgroud)

java android phonegap-plugins cordova

6
推荐指数
1
解决办法
3054
查看次数

音频无法在Android上使用phonegap播放,但在iOS上运行正常

它适用于iOS.

我看了很多答案,包括这两个:

在适用于Android的Phonegap应用上播放声音

HTML5音频无法在PhoneGap App中播放(可以使用Media?)

我尝试了所有的解决方案:

  • 更改/android_asset/www/Android 的路径
  • 使用.ogg文件
  • 使用play()/ pause()预加载音频.
  • 使用Cordova/Phonegap提供的Media插件

这是我目前的代码:

if(device.platform === "Android")   //DIFFERENT PATH FOR ANDROID
{
    url = "/android_asset/www/sound.ogg";
}else{
    url = "sound.mp3";
}
alert(url);
sound = new Media(url);
sound.play();
Run Code Online (Sandbox Code Playgroud)

有人有想法?感觉就像我一直绕圈子一样

audio html5 android phonegap-plugins cordova

6
推荐指数
1
解决办法
2426
查看次数

跨源请求被阻止原因:CORS预检信道未成功

我创建了一个phonegap应用程序,我正在调用WCF服务,该服务位于nopCommerce插件中.

我在发送api请求时遇到以下错误:

跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS预检频道没有成功).

跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS请求失败).

使用Ajax进行API调用

$.ajax({
  crossDomain: true,
  type: "POST",
  contentType: "application/json",
  async: false,
  url: "http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData",
  data: "{storeId:" + storeId + ", languageId:" + languageId + ", customerId:" + customerId + "}",            
  //data: { storeId: storeId, languageId: languageId, customerId: customerId },
  dataType: 'json',
  //jsonp: false,
  success: function (data) {
      alert(data.d);                
  },
  error: function (xhr, textStatus, error) {
      alert("Error! " + error);                
  }
});
Run Code Online (Sandbox Code Playgroud)

我通过谷歌的一些研究在我的Web.config文件中添加了以下内容.

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
  </customHeaders>
</httpProtocol> …
Run Code Online (Sandbox Code Playgroud)

wcf cross-domain nopcommerce phonegap-plugins

6
推荐指数
1
解决办法
2万
查看次数

Phonegap:Canvas无法正常刷新

我正在Phonegap中做一个Android应用程序.在画布中,我通过触摸制作了一个动态图像.我在具有不同版本的设备中进行了测试

当我运行4.1,4.2或4.3时,图像在移动时会复制.所有其他版本都可以

我尝试应用画布背景颜色和不透明度,但仍然重复

对此有什么解决方案吗?

提前致谢

javascript canvas html5-canvas phonegap-plugins

6
推荐指数
1
解决办法
60
查看次数

播放通过PhoneGap FileTransfer上传的视频时出错

我一直坚持这个问题,我似乎无法找到解决方案.我想要实现的是:

  1. 从手机库中选择一个视频
  2. 使用签名的PUT URL将视频上传到Amazon AWS
  3. 下载上传的视频并在PC上播放

我可以从手机的图库中选择视频,并成功将其上传到亚马逊aws.但是,当我尝试打开并播放文件时,媒体播放器会说不支持文件格式.

它不能成为我的播放器的编解码器问题,因为我可以播放上传到亚马逊的其他视频(通过标准HTML文件输入).另外,当我将同一视频从手机传输到桌面时,它可以播放.

我有一种感觉,我在设置FileTransfer对象时错过了一些东西.以下是我的代码片段:

navigator.camera.getPicture(
function(imgUrl) {
    that.mDialogOpen("Uploading video...");
    window.resolveLocalFileSystemURL(imgUrl, function(fileEntry) {
        fileEntry.file(function(file) {
            var parts       = fileEntry.nativeURL.split('/');
            var filename    = parts[parts.length - 1];

            // Params is sent to the server to generate the signed amazon put url
            var params      = {'a':'handlerFunctionKey', 'name':filename, 'type':'multipart/encrypted'};

            var callback = function(data) {
                alert("In callback");
                var dataResp = data['handlerFunctionKey'];
                if (dataResp.status == 'SUCCESS') {
                    var amazonUrl = decodeURIComponent(dataResp.object);

                    alert("Setting up options: " + file.type);
                    var ftOptions           = new FileUploadOptions(); …
Run Code Online (Sandbox Code Playgroud)

video android file-transfer phonegap-plugins cordova

6
推荐指数
0
解决办法
68
查看次数