This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support android shortcut badges on supported devices when app is closed #703
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32c5f94
Just testing that we can actually change and install the new plugin l…
yossale 765ae7b
add badge count handling
yossale 08e6524
handle bagde count
yossale 8353f42
handle string value to int
yossale 0241568
fix int declaration
yossale f29a435
use single build gradle
yossale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2013-2016 by appPlant UG. All rights reserved. | ||
* | ||
* @APPPLANT_LICENSE_HEADER_START@ | ||
* | ||
* This file contains Original Code and/or Modifications of Original Code | ||
* as defined in and that are subject to the Apache License | ||
* Version 2.0 (the 'License'). You may not use this file except in | ||
* compliance with the License. Please obtain a copy of the License at | ||
* http://opensource.org/licenses/Apache-2.0/ and read it before using this | ||
* file. | ||
* | ||
* The Original Code and all software distributed under the License are | ||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | ||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | ||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | ||
* Please see the License for the specific language governing rights and | ||
* limitations under the License. | ||
* | ||
* @APPPLANT_LICENSE_HEADER_END@ | ||
*/ | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'me.leolin:ShortcutBadger:1.1.4@aar' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
<engines> | ||
<engine name="cordova" version=">=3.6.3" /> | ||
<engine name="cordova-android" version=">=4.0.0" /> | ||
<engine name="cordova-ios" version=">=4.0.0" /> | ||
<engine name="cordova-ios" version=">=3.9.2" /> | ||
</engines> | ||
|
||
<preference name="SENDER_ID" /> | ||
|
@@ -86,6 +86,7 @@ | |
|
||
<framework src="com.android.support:support-v13:23+" /> | ||
<framework src="com.google.android.gms:play-services-gcm:+" /> | ||
<framework src="build.gradle" custom="true" type="gradleReference" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of including a custom build.gradle file why not use a framework tag:
|
||
|
||
<source-file src="src/android/com/adobe/phonegap/push/GCMIntentService.java" target-dir="src/com/adobe/phonegap/push/" /> | ||
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.java" target-dir="src/com/adobe/phonegap/push/" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import me.leolin.shortcutbadger.ShortcutBadger; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
|
@@ -57,7 +59,6 @@ public void setNotification(int notId, String message){ | |
@Override | ||
public void onMessageReceived(String from, Bundle extras) { | ||
Log.d(LOG_TAG, "onMessage - from: " + from); | ||
|
||
if (extras != null) { | ||
|
||
SharedPreferences prefs = getApplicationContext().getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE); | ||
|
@@ -191,16 +192,32 @@ private Bundle normalizeExtras(Bundle extras) { | |
return newExtras; | ||
} | ||
|
||
private void updateBadge(Context context, String badge) { | ||
|
||
int count = badge == null ? 0 : Integer.parseInt(badge); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make it impossible to keep the badge count unchanged (eg. when it's not set) |
||
|
||
if (count > 0) { | ||
ShortcutBadger.applyCount(context, count); | ||
} else if (count == 0) { | ||
ShortcutBadger.removeCount(context); | ||
} | ||
} | ||
|
||
|
||
private void showNotificationIfPossible (Context context, Bundle extras) { | ||
|
||
// Send a notification if there is a message or title, otherwise just send data | ||
String message = extras.getString(MESSAGE); | ||
String title = extras.getString(TITLE); | ||
String contentAvailable = extras.getString(CONTENT_AVAILABLE); | ||
String badgeCount = extras.getString(COUNT); | ||
|
||
Log.d(LOG_TAG, "message =[" + message + "]"); | ||
Log.d(LOG_TAG, "title =[" + title + "]"); | ||
Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]"); | ||
Log.d(LOG_TAG, "badgeCount =[" + badgeCount + "]"); | ||
|
||
updateBadge(context, badgeCount); | ||
|
||
if ((message != null && message.length() != 0) || | ||
(title != null && title.length() != 0)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import android.util.Log; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import. |
||
import com.google.android.gms.gcm.GcmPubSub; | ||
import com.google.android.gms.iid.InstanceID; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, for version 1.6.0 and greater of this plugin we'll only support cordova-ios 4.0.0 or greater. Please revert line.