katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.75k forks source link

reopen app problem,is it a Android terrible problem? #30

Closed bau720123 closed 10 years ago

bau720123 commented 10 years ago

ios,ipad mini 7.04 Android,HTC Sensation XL 4.03

when I call this methoid,window.plugin.notification.local.add({ message: 'Great app!' });

in ios, the status bar show the notification,and I click it(the notification message will "disappear"),it will "reback" to the original app,seems everything is OK

but in Android,the status bar show the notification too,and I click it(the notification message will "not disappear"),it will "reopen" another the original app(because of when I click it,it will show the splashscreen and do some initial function again),when I close the another the original app,it seems will "reback" to the original app,just like this address,Then the screen does not move, except when I press the Back or Home button http://www.littlebau.com/reopen.png

mithiljadhav commented 10 years ago

Check here: https://github.com/katzer/cordova-plugin-local-notifications#app-restarts-on-android-after-notification-was-clicked

The launch mode for the main activity has to be set to singleInstance

<activity android:launchMode="singleInstance"...

bau720123 commented 10 years ago

thanks a lot but....because of I am just only use phonegap build(Not phonegap Eclipse or phonegap xcode) so...I can't set this line,<activity android:launchMode="singleInstance"...,to my config.xml is there any solution to solve this problem only through "phonegap build"~tks~

Mac956 commented 10 years ago

Like mithiljadhav said, you have to add: android:launchMode="singleInstance" on the activity section to the AndroidManifest.xml which is located in yourappfolder\platforms\android, i'm also using phonegap without eclipse. You have to edit the file yourself with a text editor like notepad or notepad++.

bau720123 commented 10 years ago

thanks for Mac956 but...all of are the "Garbled" look the picture,you will know what I mean.... http://www.littlebau.com/Garbled.jpg

Mac956 commented 10 years ago

You are looking in the wrong folder, you have to edit it before compiling your app, in your project folder,

myapp\ -----------.cordova\ -----------merges\ -----------platforms\ --------------------------android\AndroidManifest.xml -----------plugins\ -----------www\

bau720123 commented 10 years ago

..... I am only use "phonegap build" https://build.phonegap.com in phonegap build,there is no such folder like that

by the way,in phonegap build,only add this line to your config.xml that you can use the local-notifications plugin https://build.phonegap.com/plugins/331

Mac956 commented 10 years ago

Ok, i think i found what you need: http://pervasivecode.blogspot.mx/2011/11/phonegap-build-editing.html now you can edit the AndroidManifest.xml and insert android:launchMode="singleInstance" in the activity

abe-pleasant commented 10 years ago

I am also having this "black screen" problem (I think the title of this issue should be changed because it is currently not very descriptive.)

I am using Phonegap build 3.0, LocalNotifications 0.6.2, Android 4.4.

Is editing the AndroidManifest.xml the only way to accomplish this? Is it possible that there is another fix that makes this plugin usable for Phonegap Build?

(Further note: There seems to be a problem with launchMode="singleInstance" in that it stops the camera from working, and someone said to use launchMode="singleTask" instead.. https://groups.google.com/forum/#!topic/phonegap/8E5C6phqQA4)

EDIT: I am confident that we can fix this without having to play around with AndroidManifest.xml. I am using another phonegap plugin in my app, PushPlugin, which also creates OS notifications. When those are tapped the app is opened, and only if needed the activity is reloaded. https://github.com/phonegap-build/PushPlugin/blob/master/src/android/com/plugin/gcm/PushHandlerActivity.java

katzer commented 10 years ago

I think it shall be possible programmatically with the right intent flags. But for the moment I tried different flags without success.

katzer commented 10 years ago

@abe-pleasant the "black screen" problem is another one. That should be fixed now after the release of v0.6.2

abe-pleasant commented 10 years ago

@katzer I am using the latest one on Phonegap Build, which seems to be version 0.6.2.

When I tap a notification it opens another activity and that activity is just an empty black screen, and the JS handler is not called.

It seems to me like the issues are probably related?

katzer commented 10 years ago

@abe-pleasant That bug was solved (#23, #25). But v0.6.2 contains that bug.

I want release the version 0.6.3, but before the issue #14 needs to be fixed.

bau720123 commented 10 years ago

thanks @Mac956 @abe-pleasant @katzer

now I use the apktool to Decryption my "AndroidManifest.xml",finally I install the apk file to the Android machine but I met some problem...

Let me explain the purpose of each file and folder first http://www.littlebau.com/apktool/01.gif

The "phonegap_decode" folder is the result location after I decode the original phonegap.apk file

The "phonegap_encode" folder is the result location after I modify the Decryption "AndroidManifest.xml" and save and rebuilt to the new phonegap.apk file

The "phonegap_resign" folder is the result location after I re-sign the encode "phonegap.apk" file

The "android.keystore" is my Android key,and it is no problem with the phonegap build

The "aapt.exe"、"apktool.bat"、"apktool.jar" are all the apktool related file,and I use 1.52 version https://code.google.com/p/android-apktool/downloads/list

The "phonegap.apk" is my original Android .apk file that downloaded from phonegap build,and it is no problem install on the Android phone or tablet

first step,I use this command line to decode my phonegap.apk to "phonegap_decode" folder location,and it is success

apktool d -f phonegap.apk phonegap_decode/

http://www.littlebau.com/apktool/02.gif http://www.littlebau.com/apktool/03.gif

second step,I use this command line to encode my "phonegap_decode" folder to a new encode phonegap.apk that location to "phonegap_encode" folder,and it is success but seems have a little problem

apktool b -f phonegap_decode/ phonegap_encode/phonegap.apk

http://www.littlebau.com/apktool/04.gif

third step,I use this command line to resign my "phonegap_encode" folder's phonegap.apk to a new resign phonegap.apk that location to "phonegap_resign" folder,and it is success

jarsigner -verbose -keystore android.keystore phonegap_resign/phonegap.apk littlebau

http://www.littlebau.com/apktool/05.gif

final step,I upload the "phonegap_resign/phonegap.apk" to my Android machine,and install it,but still can't install http://www.littlebau.com/apktool/06.png

by the way,when I upload the "phonegap_resign/phonegap.apk" to the google,it will fail too

please give me some suggestion or help

bau720123 commented 10 years ago

any feedback?

abe-pleasant commented 10 years ago

@bau720123 You use phonegap build? Maybe wait until the plugin is at 0.6.3: https://build.phonegap.com/plugins/331 then try again? According to what was mentioned here that should solve at least one of the two issues...

You can tell phonegap build to hurry up with their approval of that version, see here: http://community.phonegap.com/nitobi/topics/how_long_does_it_take_to_approve_plugin_updates

(And either way I don't think it's a good idea to invest time into a solution involving repackaging the APK manually, we want this to work with phonegap build as is, and that should be completely possible).

katzer commented 10 years ago

EDIT: I am confident that we can fix this without having to play around with AndroidManifest.xml. I am using another phonegap plugin in my app, PushPlugin, which also creates OS notifications. When those are tapped the app is opened, and only if needed the activity is reloaded. https://github.com/phonegap-build/PushPlugin/blob/master/src/android/com/plugin/gcm/PushHandlerActivity.java

The implementation how the launch intent is started is the same as for PushPlugin. Maybe someone with Android expertise knows how to solve that without modifying the manifest?

abe-pleasant commented 10 years ago

@katzer, I don't have a local dev environment set up for this, so I can't try it myself. But upon comparing the code here https://github.com/katzer/cordova-plugin-local-notifications/blob/master/src/android/ReceiverActivity.java#L51 with PushPlugin's corresponding sections, it seems that maybe removing that second call to launchMainIntent() would solve the issue?

Edit: also PushPlugin doesn't seem to use any intent flags, maybe we can get rid of those if they are unnecessary? (https://github.com/katzer/cordova-plugin-local-notifications/blob/master/src/android/ReceiverActivity.java#L64)

bau720123 commented 10 years ago

thanks @abe-pleasant

Really thank you for your hard work I have also been left a message on the forum,and ask Phonegap team more hurry up

I will study the repackaging way just because of @Mac956 let me know the "apktool",I am also thanks to him,And find a lot of things by myself,but Just some error happened last...,if that can work with phonegap build as is,I think this is the best choice too

I am also used the "PushPlugin",it is a good plugin too but the "local-notifications" is also a good plugin,some feature that the "PushPlugin" can't be done

katzer commented 10 years ago

@abe-pleasant I have tested it without flags and many other flags. But it results always in the same behavior.

abe-pleasant commented 10 years ago

Just wanted to report that this is still an issue on android 4.4, with version 0.6.3 of the plugin and phonegap 3.0.

Can @katzer (or someone who can test locally) please try removing the second call to launchMainIntent() as I mentioned a couple comments ago? It is the only difference I found between the code here and in PushPlugin.

katzer commented 10 years ago

@abe-pleasant I have removed it (dd0691b86cdcca18e2c6a8c2e6d59b714796b0b2)

Ionas83 commented 10 years ago

I m using phonegap build 3.1.0, local-notification plugin 0.6.3, and testing on android 4.1.2.

The problem with the black screen still exists for me: while the application is open or minimized, when I tap on the notification in status bar, it opens another activity and that activity is just an empty black screen. I have to hit the back button to return to the application and with that the background function is executed as well.

Isn't this fixed yet?

Will editing the AndroidManifest.xml like described here http://pervasivecode.blogspot.mx/2011/11/phonegap-build-editing.html do the trick? - this is a really bad workaround though.

thx!

abe-pleasant commented 10 years ago

@Ionas83 version 0.6.3 (the latest on phonegap build) still has the problem.

Editing the manifest as you linked should make it work, I personally haven't tried it.

The change made by @katzer (mentioned 2 comments ago) might fix it, but I have no local build environment setup to try it. I am waiting until I have time to setup a local build environment, or until someone else who can build locally is kind enough to test it. (By the way, what @katzer changed is slightly different than my suggestion, but I can't really say if my suggestion would be any better).

katzer commented 10 years ago

Changing the launch mode solves that issue.

Maybe there is a better, PGB valid solution. But I don't now how. Everyone is welcome to solve that issue!!!

Ionas83 commented 10 years ago

It's a pity it's a really nice plugin! i hope somebody finds a fix for this :)

Also in android, while the application is closed, when you tap on the notification in status bar, the application starts but the background function is not executed. This could be an important addition to the plugin. The pushplugin has already implemented this operation.

p.s. there is another "local-notifications" plugin on phonegap build by katzer only for android with a newer version. https://build.phonegap.com/plugins/381 what's the difference? does it solve the black screen issue?

katzer commented 10 years ago

No, I think they could not wait for v0.7.0. Thats why they have submitted a prerelease version of that plugin only for Android.

bau720123 commented 10 years ago

Hello everyone,let me to explain my detail Testing Process,if anything I did the wrong code,please let me know

(that me called it the "before" situation,and you can search the keywords,and there is no "android:launchMode")

<activity android:name="de.appplant.cordova.plugin.localnotification.ReceiverActivity"/>

the AndroidManifest.xml that I never modify it => http://www.littlebau.com/android/before/AndroidManifest.xml

(that me called it the "after" situation,and you can search the keywords,and I add the "android:launchMode")

<activity android:name="de.appplant.cordova.plugin.localnotification.ReceiverActivity" android:launchMode="singleInstance"/>

the AndroidManifest.xml that I did some modify => http://www.littlebau.com/android/after/AndroidManifest.xml

when I am in "before" situation,and click the status bar Android 4.0.3:the status bar icon not disappear,And immediately "reopen" my app again,But it stops at this screen does not move... http://www.littlebau.com/reopen.png unless I press the Back button that the "black" screen will disappear and reback to my original app Android 4.1.1:the status bar icon not disappear,And immediately "reopen" my app again,But no black screen

when I am in "after" situation,and click the status bar,Something has really change Android 4.0.3:the status bar icon not disappear too,And immediately "reback" to my original app (looks great),But if I press the Home button to switch my desktop... http://www.littlebau.com/desktop.png and click my app icon,it will reopen the app again.... Android 4.1.1:as same as above

bau720123 commented 10 years ago

Hello everyone again,I have solve the problem the => android:launchMode="singleInstance" must be add to the main (the "first" activity Tag in the AndroidManifest.xml)

@katzer I am already solve the problem,but really have a little issue,when I click the status bar,the status bar's icon still not disappear but your another plugin "badge" https://build.phonegap.com/plugins/384 it will disappear so...is it a code problem by "local-notifications" ? could bother you to check out for a while ?

@Ionas83 what is your "background function"? I have no such kind of problem like yours

@Mac956 I've been using the apktool software tool very skilled,tks~

to everybody I have post a topic about the "android:launchMode" problem to phonegap team,let me to see if anything could be changed http://community.phonegap.com/nitobi/topics/could_definitions_the_androids_android_launchmode_by_myself_in_the_future_by_phonegap_builds_config_xml

Ionas83 commented 10 years ago

@bau720123

While the app is closed (not minimized) and you get a notification, when you tap on it, it opens the application on index.html page but the background function is not executed. Foreground function is executed when the app is already open. Backgound function is executed when the app is minimized.

You can see the code below:

window.plugin.notification.local.add({ id: 6666, title: 'Reminder', message: 'You have a meeting in one hour!', date: _60_seconds_from_now, foreground: 'foreground', background: 'background' });

function background (id) { alert('I WAS IN THE BACKGROUND ID='+id); }

bau720123 commented 10 years ago

@Ionas83

try these code first,I am really no problem,this will happen after 15 secconds I want to ask you a question too,when you click the status bar,the status bar's icon will disappear or not ?

function abc()
{
var mysecond = 15;
var now = new Date().getTime();
var timer = new Date(now + mysecond * 1000);

 window.plugin.notification.local.add(
 {
 id: mysecond,
 title: 'Reminder',
 message: 'You have a meeting in one hour!',
 date: timer,
 foreground: 'foreground',
 background: 'background',
 });
}

function foreground ()
{
alert('I WAS IN THE FOREGROUND');
}
function background ()
{
alert('I WAS IN THE BACKGROUND');
}
Ionas83 commented 10 years ago

@bau720123 I tried your code but what it does for me is this: background function executes the moment you add a notification. I need background function to execute when you tap a status bar's icon while the app is closed.

Summarizing my problems:

1) The status bar's icon won't disappear on android or iOS devices. (haven't tried windows devices yet) 2) The alert sound doesn't play on iOs devices when a notification is received. 3) I get a black screen when I tap on the status bar's icon while the application is open or minimized. 4) Still the background function is not executed when you tap on a status bar's icon while the app is closed (android and iOS). Can anybody else verify this?

(as I read, issues 2 and 3 exist only for those using Phonegap Build)

bau720123 commented 10 years ago

@Ionas83

I have been modify the code 1) yes,the status bar's icon won't disappear,must be look for the @katzer help 2) no,the ios have it's default sound,although I set it,but still the default sound,must be look for the @katzer help 3) must set android:launchMode="singleInstance" into your AndroidManifest.xml,In addition, no other way (for now) http://community.phonegap.com/nitobi/topics/could_definitions_the_androids_android_launchmode_by_myself_in_the_future_by_phonegap_builds_config_xml 4) it look like that the background can be trigger only in "not close the app" situation,must be look for the @katzer help

katzer commented 10 years ago

Puh, much to much...

@bau720123

when I click the status bar, the status bar's icon still not disappear

You have to set autoCancel to true. With v0.6.3 you to cancel notifications manually.

android:launchMode="singleInstance" must be add to the main (the "first" activity Tag in the AndroidManifest.xml)

https://github.com/katzer/cordova-plugin-local-notifications#app-restarts-on-android-after-notification-was-clicked

@bau720123, @Ionas83

With v.0.6.3 the exec of the background callback, if the app was not running, isn't supported. That ability has been added later.

katzer commented 10 years ago

Setting the launchMode for the ReceiverActivity activity is a great idea. I tried it and it solves the problem. The mode can be set by the plugin so PGB users can use it too.

Ionas83 commented 10 years ago

@katzer

With v.0.6.3 the exec of the background callback, if the app was not running, isn't supported. That ability has been added later.

by "later" you mean a newer version of the plugin that is not on PGB yet?

Setting the launchMode for the ReceiverActivity activity is a great idea. I tried it and it solves the problem. The mode can be set by the plugin so PGB users can use it too.

how can PGB users set the launchMode without editing the AndroidManifest.xml file? I didn't get it!

thx in advance!

bau720123 commented 10 years ago

@katzer set the launchMode for the ReceiverActivity activity is Not exactly a good idea

one Because of if I press the Home button to switch my desktop... http://www.littlebau.com/desktop.png it will reopen app again the Detailed operating procedures I have said above...

two not every phonegap plugins all determine ReceiverActivity in AndroidManifest.xml your another "badge" plugin would not

katzer commented 10 years ago

@Ionas83 "later" means a new version or the current state of master branch.

To me it looks as solved now. There is no need anymore to edit the AndroidManifest.xml.

katzer commented 10 years ago

@bau720123

The plugin handles the action if a notification is pressed. And that works now without setting the launchMode. The action if the user presses the app icon on the home screen is not controlled by the plugin.

Ionas83 commented 10 years ago

@katzer

So, if I understood correctly, regarding the black screen problem, it's been fixed and now there is no need to edit the AndroidManifest.xml but the fix is in the current state of master branch so... PGB users have to wait until the new plugin version is added in PGB website. Correct?

katzer commented 10 years ago

Correct!

bau720123 commented 10 years ago

Hey everybody I have post a suggestion about the "android:launchMode" problem to the phonegap team https://github.com/phonegap/build/issues/252#issuecomment-33539796

it Seems to be that we can define the "android:launchMode" option In the config.xml(build.phonegap.com) In the future

bau720123 commented 10 years ago

Hey everybody it really got work by phonegap build itself https://github.com/phonegap/build/issues/252#issuecomment-33539796 I love phonegap~