Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 33

0
votes
answers
16 views
+10

Uncaught SyntaxError: Unexpected token > when loading Phonegap app on Android phone

--- UPDATE ---

Error disappeared when setting NODE_ENV=production before my webpack build-step. I still don't know what the underlying cause for this issue was.

--- END UPDATE ---

I have made a Phonegap app using Webpack. The app works fine on iOS and other Android devices, but it crashes on a Huawei Honor H60-L04 with Android 4.4.2. It crashes on load, showing this error:

Uncaught SyntaxError: Unexpected token >

By adding/removing all scripts loaded in index.html one by one, I have isolated the problem to exist in the dist/build.js file. That is the resulting js file from Webpack build, with all the app logic inside. Is there some webpack config mistake causing this issue? And why is only this device getting the error?

If relevant, I am using Vue.js and Framework7 to develop the app, and Phonegap Build to build it.

--- UPDATE --- :

When remote debugging the console says the error is at line 85 in index.html, but the index.html is not that long. Guessing that line number reports that way because dynamic things are added to the html-file when trying to load script.

My entire .babelrc file:

{
  "plugins": ["transform-es2015-shorthand-properties"]
}

My entire Webpack config file:

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  performance: {
    hints: false
  },
  module: {
    rules: [
      {
        test: /.vue$/,
        loader: 'vue-loader',
        options: {
          sass: "vue-style-loader!css-loader!sass?indentedSyntax"
        }
      },
      {
        test: /.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /.(png|jpg|gif|svg)$/,
        loader: 'file',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue',
      'Framework7Vue': path.join(__dirname, '/node_modules/framework7-vue/dist/framework7-vue.min.js')
    }
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

--- END UPDATE ---

0
votes
answers
13 views
+10

How can i get phonegap-plugin-push senderID

How can i get phonegap-plugin-push senderID

i tried looking on internet but none of them seems to be working , may be google has updated something .

https://console.developers.google.com

have created a new project here .

after i went inside dashboard . I see the message No APIs or services are enabled .

can anyone please guide .

this is my code where i'm trying to replace my sender id

console.log('calling push init');
var push = PushNotification.init({
    "android": {
        "senderID": "XXXXXXXX"
    },
    "browser": {},
    "ios": {
        "sound": true,
        "vibration": true,
        "badge": true
    },
    "windows": {}
});
console.log('after init');

push.on('registration', function(data) {
    console.log('registration event: ' + data.registrationId);

    var oldRegId = localStorage.getItem('registrationId');
    if (oldRegId !== data.registrationId) {
        // Save new registration ID
        localStorage.setItem('registrationId', data.registrationId);
        // Post registrationId to your app server as the value has changed
    }

    var parentElement = document.getElementById('registration');
    var listeningElement = parentElement.querySelector('.waiting');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');
});

push.on('error', function(e) {
    console.log("push error = " + e.message);
});

push.on('notification', function(data) {
    console.log('notification event');
    navigator.notification.alert(
        data.message,         // message
        null,                 // callback
        data.title,           // title
        'Ok'                  // buttonName
    );

});

Thanks in advance .

0
votes
answers
19 views
+10

Push notification Click event is not working when app is in Background in PhoneGap

I am using phonegap-plugin-push plugin for FCM push notification,

Here I am able to get notification when app is running in background or app is in active status notification is working fine in this state.

But when app is in background state and any notificaiton came in that condition if any user click on the notificaiotn he must be redirect on any spacific page, for this I try so many way but its not working .

I am using following code to initialize notification

var push = PushNotification.init({ android: { senderID: '436009364694', alert: true, badge: true, icon: 'icon', sound: true, vibrate: true }, ios: { alert: "true", badge: "true", sound: "true", vibrate: true, clearBadge: true }, windows: {} });

And I am using following code to trigger the notification

push.on('notification', function(data) { });

above code is only working when app is in running state but its not working when app is in background,

Any one know how to trigger click event if app in background state

0
votes
answers
33 views
+10

cordova javascript shows Uncaught TypeError: Cannot read property

I am developing a cordova app. In this app i am call a website. web page is coming correctly the page have an a button. I want to show an a alert when the button click. The web page button code is shown below. In web there is no button click is defined.

<p><a class="btn btn-primary btn-lg">Take Picture &raquo;</a></p>

The cordova code is

var app = {
    // Application Constructor
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener('deviceready', this.onDeviceReady, false);        
    },
    onDeviceReady: function () {
    app.receivedEvent('deviceready');
    // Here, we redirect to the web site.
    var targetUrl = "http://mysite/mypage.php/";
    var bkpLink = document.getElementById("bkpLink");
    bkpLink.setAttribute("href", targetUrl);
    bkpLink.text = targetUrl;
    window.location.replace(targetUrl);
    //I want to call a alert when button click      
    document.getElementsByClassName('btn-lg')[0].addEventListener('click', (function(i) {
    return function() {
        alert("okkkkkkkkkk");
    };
    })(i), false);  

    },
    // Note: This code is taken from the Cordova CLI template.
    receivedEvent: function (id) {
    }

};
app.initialize();

When running this code it shows the Uncaught TypeError: Cannot read property 'addEventListener' of undefined", source: file:///android_asset/www/js/index.js

I don't how to solve this problem. Please help me.

0
votes
answers
18 views
+10

Phonegap is unable to install cordova plugins: The platform “browser” does not appear to be a valid cordova platform

I'm not able to install new plugins in Phonegap with the command: $ phonegap plugin add **.

For example, when I run $ phonegap plugin add cordova.plugins.diagnostic, the following error occurs:

Installing "cordova.plugins.diagnostic" for browser  


Unable to load PlatformApi from platform. Error: Cannot find module '/Users/george/Documents/phonegap/TryPushNotifications/platforms/browser/cordova/Api.js'  


Failed to install 'cordova.plugins.diagnostic': Error: Unhandled "error" event. (The platform "browser" does not appear to be a valid cordova platform. It is missing API.js. browser not supported.)  
    at EventEmitter.emit (events.js:185:19)  
    at EventEmitter.module.exports.emit (/usr/local/lib/node_modules/phonegap/node_modules/cordova-common/src/events.js:71:17)  
    at Object.getPlatformApiFunction (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/cordova/util.js:500:20)  
    at Object.getPlatformApi (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/platforms/platforms.js:55:25)  
    at handleInstall (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:593:29)  
    at /usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:357:28  
    at _fulfilled (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:787:54)  
    at self.promiseDispatch.done (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:816:30)  
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:749:13)  
    at /usr/local/lib/node_modules/phonegap/node_modules/q/q.js:509:49  


Error: Unhandled "error" event. (The platform "browser" does not appear to be a valid cordova platform. It is missing API.js. browser not supported.)  

It seems like Phonegap didn't add a valid browser file, but I also try to create a new project with the phonegap command (which automatically creates a new push notifications project and same result).

How can I solve this?

Thank you.

0
votes
answers
13 views
+10

PhoneGap audio lag

I use javascript to play a short sound on my app:

var audio = new Audio('sound.mp3');
audio.play();

When the above code is called, the whole app gets a lag/delay. After about 200-500ms the app continues as normal and plays the sound. After playing the sound for 2-3 times it seems to have cached or something, because then it works as it should without a lag.

This happens when testing in PhoneGap app for iOS. Running in Chrome desktop it works good.

沙发
0
+50

You may consider loading the sound when you app is launched and keep it in the cache. Then, just play it when needed. That should reduce the lap or even omit it.

謝謝。我沒有找到一個很好的解決方案,將聲音加載到緩存,所以我可以嘗試,你知道如何? - Rasmus於2017年10月3日14:30

這個插件可能非常有幫助:github.com/floatinghotpot/cordova-plugin-nativeaudio - Mohamed Chaawa 2017年10月3日14:36

0

Basically, the 200-500 ms delay is not a bug or a performance issue, it's a feature necessary to detect the possible double tap.

The solution to get rid of that delay is:

1) To use a combination of touch events instead of the click event, Or

2) Touse fastClick if you don't have jQuery Mobile.

3) If fastclick doesn't work, use this:

      $('yourElement').on( 'touchstart', function ( startEvent ) {});

我已經使用了fastclick和touchstart。這不僅僅發生在touchstart上,當音頻播放時沒有任何觸摸也會發生延遲。 - Rasmus 17年9月26日10:50

這可能是App緩存的問題。嘗試玩這個。這可能有所幫助。 - Vikas Yadav 17年9月26日12:27

我認為靈魂就是你所說的。在播放之前需要對聲音進行追逐。第一次加載聲音是造成延遲的原因。 - Rasmus於2017年10月2日9:27

0

Since this is a mp3 link device needs to download file before playing it, so the lag. if you want to play music without lag you need streaming media.

Wowza server allows you to setup streaming media using m3u8 (HLS) protocol.

0
votes
answers
18 views
+10

404 error when creating new cordova project

I am getting this error when trying to create a new cordova project:

Downloading cordova library for www...
Error: HTTP error 404 retrieving version 3.6.3 of cordova for www
at Request._callback (/usr/share/cordova-cli/node_modules/cordova-lib/src/cordova/lazy_load.js:251:30)
at Request.self.callback (/usr/share/cordova-cli/node_modules/cordova-lib/node_modules/request/request.js:372:22)
at Request.emit (events.js:160:13)
at Request.<anonymous> (/usr/share/cordova-cli/node_modules/cordova-lib/node_modules/request/request.js:1310:14)
at Request.emit (events.js:165:20)
at IncomingMessage.<anonymous> (/usr/share/cordova-cli/node_modules/cordova-lib/node_modules/request/request.js:1258:12)
at IncomingMessage.emit (events.js:165:20)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:152:19)

The command I am using to create the project is this:

cordova create hello com.example.hello HelloWorld

I am on ubuntu 16.04.2 and my cordova version is 4.3.1

Any help will be appreciated, thanks !

沙发
0

4.3.1 is the old (and probably deprecated) version of Cordova. I think you should update this package: sudo npm install -g cordova

嘿,是的。我總結說這與我的操作系統有關,這個系統太舊了。我需要從更新我的操作系統開始。感謝您的回答 ! - SilviuU 18年3月16日16:31

板凳
0

I had the same issue, and after following steps it works good for me:

  1. update packages (just to be sure, that all is up to date): sudo npm install -g cordova
  2. reboot your PC

嘿。我開始這樣做,發現它可能是我的操作系統,不支持很多東西的新版本。謝謝你的回答,它讓我找到了解決問題的正確途徑。 - SilviuU 18年6月16日16:32

地板
0

To answer the original question and for those stuck maintaining old projects (on cordova 4.3.1) and can't upgrade cordova, this is due to "create" trying to get the "hello world" project from a dead url:

https://git-wip-us.apache.org/repos/asf?p=cordova-app-hello-world.git;a=snapshot;h=3.6.3;sf=tgz

To work around this in these older versions create the project with --src which prevents fetching this "hello world" www project:

cordova create --src=<path-to-your-www> myapp

0
votes
answers
25 views
+10

Phonegap (build) large splashscreen makes Android app crash

I set up splashscreens for my Phonegap app with the splashscreen Cordova plugin, built with "Phonegap Build".

In the splashscreen plugin docs they only mention pixel densities up to xhdpi, but recent devices go up to xxxhdpi.

So I added an xxxhdpi splashscreen image.

Now the app seems to crash on those devices on startup, and I think this is due to the large splashscreen.

java.lang.RuntimeException: at android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas.java:260) at android.graphics.Canvas.drawBitmap (Canvas.java:1420) at android.graphics.drawable.BitmapDrawable.draw (BitmapDrawable.java:545) at android.widget.ImageView.onDraw (ImageView.java:1286) at android.view.View.draw (View.java:18319) at android.view.View.updateDisplayListIfDirty (View.java:17297) at android.view.View.draw (View.java:18081) at android.view.ViewGroup.drawChild (ViewGroup.java:3966) at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3752) at android.view.View.updateDisplayListIfDirty (View.java:17292) at android.view.View.draw (View.java:18081) at android.view.ViewGroup.drawChild (ViewGroup.java:3966) at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3752) at android.view.View.updateDisplayListIfDirty (View.java:17292) at android.view.View.draw (View.java:18081) at android.view.ViewGroup.drawChild (ViewGroup.java:3966) at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3752) at android.view.View.draw (View.java:18322) at com.android.internal.policy.DecorView.draw (DecorView.java:854) at android.view.View.updateDisplayListIfDirty (View.java:17297) at android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:666) at android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:672) at android.view.ThreadedRenderer.draw (ThreadedRenderer.java:780) at android.view.ViewRootImpl.draw (ViewRootImpl.java:3112) at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2908) at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2502) at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1509) at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7051) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:927) at android.view.Choreographer.doCallbacks (Choreographer.java:702) at android.view.Choreographer.doFrame (Choreographer.java:638) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:913) at android.os.Handler.handleCallback (Handler.java:751) at android.os.Handler.dispatchMessage (Handler.java:95) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6692) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)

In other questions I found the following suggestion:

Move your image in the (hi-res) drawable to drawable-xxhdpi

But using Phonegap Build, I don't see how I could do that. Is it not possible to have such large files? Should I remove the highest pixel densities? Is there an alternative?

0
votes
answers
31 views
+10

Phonegap - Push notification with embedded web app (InAppBrowser window)

I am wrapping an existing web app (Rails) as a cordova app in a webview. I am opening the homepage on onDeviceReady. Followed by registering for push notification.

var ref = cordova.InAppBrowser.open(window.app_url, 
                            '_blank', 'location=no,clearsessioncache=no');
setupPushNotifications(window.app_url, ref);

I am using phonegap-plugin-push for push notifications.

push.on('registration', function(data) {
    saveRegistrationId(app_url, data);
});

I would like to associate the notification registrationId in the context of a logged in user in the web app.

This seems to work without a hitch when using the phonegap developer app. But this does not make a call to the rails app to save the registrationId when I install the android-debug.apk on my device.

The content of config.xml

<access origin="*" />
<allow-navigation href="http://192.168.1.3:8000" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

I have also tried _self, to open in the same webview. It does not run setupPushNotifications.

The code for registering the token

function saveRegistrationId(app_url, data) {
    // this is our payload for the POST request to server
    // data = {registrationId: 'XXXXX', registrationType: 'FCM'}
    const device_data = Object.assign(data, this.device);

    const url = app_url + "/mobile_devices";

    navigator.notification.alert(data.registrationId);

    navigator.notification.alert(url);

    var httpRequest = new XMLHttpRequest();

    httpRequest.open('POST', url);

    httpRequest.onreadystatechange = function() {
        navigator.notification.alert('readyState : ' + httpRequest.readyState);
        navigator.notification.alert('status : ' + httpRequest.status);
        if (httpRequest.readyState>3 && httpRequest.status==200) { console.log(httpRequest.responseText); }
    };

    httpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    httpRequest.setRequestHeader('Content-Type', 'application/json');
    httpRequest.send(JSON.stringify({device: device_data}));
}
沙发
0
+50

The problem was with the content-security-policy in index.html.

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:; connect-src 'self' http://192.168.1.3:8000;">

The key was the last section

connect-src 'self' http://192.168.1.3:8000;

That allows ajax requests to be made to the web app.

0
votes
answers
9 views
+10

Content Uri to file URI cordova/phonegap

This is my Content URI ,I want to convert it to file URI

I am trying to import a attachment from gmail,so i am getting the uri from webintent but that is the content uri,iwanted to convert to file uri

I tried many approaches in various questions but still my code is not able to call get success.I am not understanding whats wrong with my code

window.plugins.webintent.getUri(function(url) {
if(url.startsWith('content://')) {
    // url is the url the intent was launched with
    alert(url);
    window.FilePath.resolveNativePath(url, function(local)
    {   deferred.resolve('file://'+result)
    },function (error)
    {
        alert("error");
    }
    );


});

Its is going into error state