ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

$cordovaLocalNotification not working on android #855

Open jamesdef opened 9 years ago

jamesdef commented 9 years ago

the following code

  $cordovaLocalNotification.schedule({
    id: 0,
    message: notifText,  
    title: notifTitle,                               
    autoCancel: true
});

gives no result neither any error message in android, but works perfectly when testing on iOs.

Anyone experiencing similiar issues?

bricktownseo commented 9 years ago

I have had an issue with trying to use local notification and push at the same time. I disabled push and local worked immediately.

On Tue, Jun 23, 2015, 12:22 AM hasandogu notifications@github.com wrote:

I am using all the other plugins successfully, so loading ngcordova before cordova.js is non-issue.

I haven't had a chance to run my app on iOS yet but on Android I get the following when I inspect the app it on Chrome. This is my first time using the local notifications plugin.

Error: [$injector:unpr] Unknown provider: $cordovaLocalNotificationProvider <- $cordovaLocalNotification <- localNotificationService

http://errors.angularjs.org/1.3.13/$injector/unpr?p0=ordovaLocalNotificationProvider%20%3C-%20%24cordovaLocalNotification%20%3C-%20localNotificationService http://errors.angularjs.org/1.3.13/%24injector/unpr?p0=ordovaLocalNotificationProvider%20%3C-%20%24cordovaLocalNotification%20%3C-%20localNotificationService

— Reply to this email directly or view it on GitHub https://github.com/driftyco/ng-cordova/issues/855#issuecomment-114362534 .

hasandogu commented 9 years ago

I don't have push installed. As soon as I use cordova.plugins.notification.local.schedule itself, it works but not the ngCordova.

DanailMinchev commented 9 years ago

@jamesdef: "autoCancel" has been removed, "message" has been renamed to "text" - Upgrade Guide and you have to use the new plugin version for ngCordova to work: de.appplant.cordova.plugin.local-notification@0.8.1

DanailMinchev commented 9 years ago

@bricktownseo @hasandogu:

I have tested (again) the $cordovaLocalNotification and it is working fine on Android and iOS (I don't have push notification plugin installed).

I am using PhoneGap Build to build my project.

I am using:

<preference name="phonegap-version" value="3.7.0" />

<gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.8.1" source="plugins.cordova.io" />

Test code:

$scope.scheduleDelayedNotification = function () {
  var now = new Date().getTime();
  var _10SecondsFromNow = new Date(now + 10 * 1000);

  $cordovaLocalNotification.schedule({
    id: 1,
    title: 'Title here',
    text: 'Text here',
    at: _10SecondsFromNow
  });
};

Tested on:

Please provide details about your $cordovaLocalNotification example code and device + libs info

jamesdef commented 9 years ago

@DanailMinchev Thanks for your response. Even after copying your exact code, iOs works fine and android doesn't do anything.

Also, when trying

 $cordovaLocalNotification.schedule({
        id: 1,
        title: 'Title here',
        text: 'Text here',
        data: {
          customProperty: 'custom value'
        }
      }).then(function (result) {
       console.log("done");
      });

the callback is never run I'm testing on a Nexus 5, running on Android L.

DanailMinchev commented 9 years ago

@jamesdef

My bower.json is:

{
  "name": "Name",
  "version": "0.0.1",
  "description": "Msg",
  "private": true,
  "dependencies": {
    "angular": "1.3.15",
    "angular-mocks": "1.3.15",
    "angular-animate": "1.3.15",
    "angular-sanitize": "1.3.15",
    "angular-ui-router": "0.2.13",
    "lodash": "3.7.0",
    "jquery": "2.1.3",
    "ionic": "driftyco/ionic-bower#1.0.1",
    "ngCordova": "0.1.17-alpha",
    "restangular": "1.5.1",
    "angular-google-maps": "2.0.19"
  },
  "resolutions": {
    "angular": "1.3.15",
    "angular-sanitize": "1.3.15",
    "angular-animate": "1.3.15",
    "lodash": "~2.4.1"
  }
}

I'm compiling against Android 5.0.1 (API level: 21) / PhoneGap 3.7.0 on PhoneGap Build and not Android 5.1.1 (API level: 22), because there is a bug with Android 5 / Crosswalk and the native plugin:

-compile:
    [javac] Compiling 59 source files to /project/bin/classes
    [javac] /project/src/de/appplant/cordova/plugin/localnotification/LocalNotification.java:495: error: cannot find symbol
    [javac]                     webView.evaluateJavascript(js, null);
    [javac]                            ^
    [javac]   symbol:   method evaluateJavascript(String,<null>)
    [javac]   location: variable webView of type CordovaWebView
    [javac] /project/src/de/appplant/cordova/plugin/localnotification/LocalNotification.java:492: error: cannot find symbol
    [javac]         webView.post(new Runnable(){
    [javac]                ^
    [javac]   symbol:   method post(<anonymous Runnable>)
    [javac]   location: variable webView of type CordovaWebView
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 2 errors

Anyway, this bug might not be related to the issue, because you are able to recompile successfully, right?

1). If you are compiling against greater version of Android 5.0.1 (API level: 21), then could you try lower one?

2). I have tried both code snippets:

          $cordovaLocalNotification.schedule({
            id: 1,
            title: 'title plugin',
            text: 'text plugin'
          }).then(function(result) {
            console.log('plugin callback result:');
            console.log(JSON.stringify(result));
          }, function(result) {
            console.log('plugin callback error:');
            console.log(JSON.stringify(result));
          }, function(result) {
            console.log('plugin callback update:');
            console.log(JSON.stringify(result));
          });

and

          $window.cordova.plugins.notification.local.schedule({
            id: 1,
            title: 'title native',
            text: 'text native'
          }, function(result) {
            console.log('native callback result:');
            console.log(result);
          });

and I'm receiving:

plugin callback result:
"OK"
native callback result:
OK

Please try them (to see if there is a problem with native plugin) and paste the result. Also try this one to confirm that the plugin is available:

    $ionicPlatform.ready(function() {
      if ($window.cordova &&
          $window.cordova.plugins &&
          $window.cordova.plugins.notification &&
          $window.cordova.plugins.notification.local) {
        console.log('Plugin available');
      }
    });

3). Please paste config.xml and bower.json (I'm not using push plugin)

4). I will try the same app on different Android phone and let you know.

@bricktownseo you said that it works, could you provide more details how do you compile the app - android version? Thank you!

@hasandogu could you try same things described above (the two code snippets with same config)? Thank you!

jamesdef commented 9 years ago

@DanailMinchev

Really appreciating your help! 1) I'm compiling against Android 5.0.2 2) tried both, no console output at all 3) config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.tesou608936" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>MapTapp</name>
  <description>&#xD;&#xD;&#xD;
        The RendezVous.mobi MapTapp Project.&#xD;&#xD;&#xD;
    </description>
  <author email="james.defauw@gmail.com" href="">&#xD;&#xD;&#xD;
      MapTapp Team&#xD;&#xD;&#xD;
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="AutoHideSplashScreen" value="true"/>
  <preference name="SplashScreenDelay" value="3000"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
  <platform name="ios">
    <icon src="resources/ios/icon/icon.png" width="57" height="57"/>
    <icon src="resources/ios/icon/icon@2x.png" width="114" height="114"/>
    <icon src="resources/ios/icon/icon-40.png" width="40" height="40"/>
    <icon src="resources/ios/icon/icon-40@2x.png" width="80" height="80"/>
    <icon src="resources/ios/icon/icon-50.png" width="50" height="50"/>
    <icon src="resources/ios/icon/icon-50@2x.png" width="100" height="100"/>
    <icon src="resources/ios/icon/icon-60.png" width="60" height="60"/>
    <icon src="resources/ios/icon/icon-60@2x.png" width="120" height="120"/>
    <icon src="resources/ios/icon/icon-60@3x.png" width="180" height="180"/>
    <icon src="resources/ios/icon/icon-72.png" width="72" height="72"/>
    <icon src="resources/ios/icon/icon-72@2x.png" width="144" height="144"/>
    <icon src="resources/ios/icon/icon-76.png" width="76" height="76"/>
    <icon src="resources/ios/icon/icon-76@2x.png" width="152" height="152"/>
    <icon src="resources/ios/icon/icon-small.png" width="29" height="29"/>
    <icon src="resources/ios/icon/icon-small@2x.png" width="58" height="58"/>
    <icon src="resources/ios/icon/icon-small@3x.png" width="87" height="87"/>
    <splash src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" height="1136"/>
    <splash src="resources/ios/splash/Default-667h.png" width="750" height="1334"/>
    <splash src="resources/ios/splash/Default-736h.png" width="1242" height="2208"/>
    <splash src="resources/ios/splash/Default-Landscape-736h.png" width="2208" height="1242"/>
    <splash src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
    <splash src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" height="768"/>
    <splash src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
    <splash src="resources/ios/splash/Default-Portrait~ipad.png" width="768" height="1024"/>
    <splash src="resources/ios/splash/Default@2x~iphone.png" width="640" height="960"/>
    <splash src="resources/ios/splash/Default~iphone.png" width="320" height="480"/>
  </platform>
  <icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
</widget>

bower.json

{
  "name": "MapTapp",
  "private": "true",
  "devDependencies": {
    "ionic": "driftyco/ionic-bower#1.0.0"
  },
  "dependencies": {
    "angular-ui-router-anim-in-out": "~0.0.13"
  },
  "resolutions": {
    "angular": ">= 1.0.8",
    "angular-animate": "1.3.13",
    "angular-sanitize": "1.3.13"
  }
}
hasandogu commented 9 years ago

Hi @DanailMinchev

Thanks so much for your help. I actually figured my problem out yesterday. It seems like a dependency injection problem with another ng-cordova plugin I was trying to add to the app without rebuilding ng-cordova.

Once I incorporated it into ng-cordova in my own fork, local notifications started working without a problem again.

DanailMinchev commented 9 years ago

@hasandogu

Thanks for the response!

@jamesdef

If direct call $window.cordova.plugins.notification.local to the plugin does not work too, this means that probably you have incorrect setup for the app and there are no problems with $cordovaLocalNotification implementation (as confirmed by @hasandogu as well).

As you can see from my previous message:

Unfortunately, I'm not sure where is the problem with your app, apparently it is not in $cordovaLocalNotification implementation.

IMHO you should isolate the problem by creating blank project and install only the required plugins, snippet from my package.json (try to install only this plugins):

"cordovaPlugins": [
    "org.apache.cordova.device@0.3.0",
    "org.apache.cordova.splashscreen@1.0.0",
    "org.apache.cordova.statusbar@0.1.10",
    "com.ionic.keyboard@1.0.4",
    "org.apache.cordova.dialogs@0.3.0",
    "de.appplant.cordova.plugin.local-notification@0.8.1"
]

This way you will see is it local notifications plugin problem or not.

DanailMinchev commented 9 years ago

This issue might be related: https://github.com/driftyco/ng-cordova/issues/860

jamesdef commented 9 years ago

just started an entirely blank project, only installing ngcordova and this plugin. When running on my Nexus 5 (Android 5.0.2) nothing happens (even console is empty), both via plugin or native... works on iPhone however

jamesdef commented 9 years ago

no clue why, but putting it in an array

        $cordovaLocalNotification.schedule([{
            id: 1,
            title: 'hi there',
            text: 'Multi Message 1 (actually only)'
        }]);

did the trick!

DanailMinchev commented 9 years ago

@jamesdef

Thank you for the information!

I can see that you have opened issue on the official native's plugin repo: https://github.com/katzer/cordova-plugin-local-notifications/issues/615

I have tested on one more device: LG Spirit 4G / Android 5.0.1 - works fine with native and ngCordova plugin.

So, total devices I've tested on which works fine:

openup commented 8 years ago

you may try with this :

cordova.plugins.notification.local.schedule({
            id: 1,
            title: 'hi there',
            text: 'Multi Message 1 (actually only)'
        });

It works for me !

braianj commented 8 years ago

solutions for this? mine is not working