├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── actionscript └── src │ └── com │ └── freshplanet │ └── ane │ └── AirPushNotification │ ├── PushNotification.as │ ├── PushNotificationCategoryActioniOS.as │ ├── PushNotificationCategoryiOS.as │ ├── PushNotificationEvent.as │ └── PushNotificationImportance.as ├── android ├── build.gradle ├── example.local.properties ├── gradle.properties ├── gradle │ ├── wrapper.gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib │ ├── build.gradle │ ├── libs │ │ ├── FlashRuntimeExtensions.jar │ │ └── amazon-device-messaging-1.1.0.jar │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ ├── com │ │ │ ├── distriqt │ │ │ │ └── extension │ │ │ │ │ └── util │ │ │ │ │ └── Resources.java │ │ │ └── freshplanet │ │ │ │ └── ane │ │ │ │ └── AirPushNotification │ │ │ │ ├── ADMHelper.java │ │ │ │ ├── CancelAllLocalNotificationsFunction.java │ │ │ │ ├── CancelLocalNotificationFunction.java │ │ │ │ ├── CheckNotificationChannelEnabled.java │ │ │ │ ├── CreateNotificationChannel.java │ │ │ │ ├── CreateNotificationTask.java │ │ │ │ ├── CreateNotificationTask_multiMsg.java │ │ │ │ ├── Extension.java │ │ │ │ ├── ExtensionContext.java │ │ │ │ ├── FCMMessagingService.java │ │ │ │ ├── FPADMMessageHandler.java │ │ │ │ ├── FPADMMessageHandlerJobBase.java │ │ │ │ ├── FPADMMessageReceiver.java │ │ │ │ ├── FetchStarterNotificationFunction.java │ │ │ │ ├── GetCanSendUserToSettings.java │ │ │ │ ├── GetNotificationsEnabledFunction.java │ │ │ │ ├── GoToNotifSettingsFunction.java │ │ │ │ ├── LocalBroadcastReceiver.java │ │ │ │ ├── LocalNotificationFunction.java │ │ │ │ ├── MultiMsgNotification.java │ │ │ │ ├── NotificationActivity.java │ │ │ │ ├── NotificationPermissionActivity.java │ │ │ │ ├── PingUrlTask.java │ │ │ │ ├── SetBadgeValueFunction.java │ │ │ │ ├── SetIsAppInForegroundFunction.java │ │ │ │ ├── SettingsLauncherActivity.java │ │ │ │ └── StoreNotifTrackingInfo.java │ │ └── me │ │ │ └── leolin │ │ │ └── shortcutbadger │ │ │ ├── Badger.java │ │ │ ├── ShortcutBadgeException.java │ │ │ ├── ShortcutBadger.java │ │ │ ├── impl │ │ │ ├── AdwHomeBadger.java │ │ │ ├── ApexHomeBadger.java │ │ │ ├── AsusHomeBadger.java │ │ │ ├── DefaultBadger.java │ │ │ ├── EverythingMeHomeBadger.java │ │ │ ├── HuaweiHomeBadger.java │ │ │ ├── LGHomeBadger.java │ │ │ ├── NewHtcHomeBadger.java │ │ │ ├── NovaHomeBadger.java │ │ │ ├── OPPOHomeBader.java │ │ │ ├── SamsungHomeBadger.java │ │ │ ├── SonyHomeBadger.java │ │ │ ├── VivoHomeBadger.java │ │ │ ├── XiaomiHomeBadger.java │ │ │ ├── ZTEHomeBadger.java │ │ │ └── ZukHomeBadger.java │ │ │ └── util │ │ │ ├── BroadcastHelper.java │ │ │ └── CloseHelper.java │ │ └── res │ │ ├── drawable-xhdpi │ │ ├── app_icon.png │ │ ├── icon72.png │ │ ├── status_icon.png │ │ └── status_icon24.png │ │ ├── layout │ │ ├── bannernotificationcontentview.xml │ │ ├── bigcontentview.xml │ │ ├── contentview.xml │ │ └── inflatelayout.xml │ │ └── values │ │ ├── push_colors.xml │ │ └── push_styles.xml └── settings.gradle ├── bin ├── AirPushNotification.ane └── AirPushNotification_multiMsg.ane ├── build ├── ant-contrib-0.6.jar ├── build.xml ├── example.build.config ├── extension.xml ├── platform-android.xml └── platform-ios.xml └── ios ├── AirPushNotification.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── AirPushNotificationMac.xcscheme ├── AirPushNotification.xcworkspace └── contents.xcworkspacedata ├── AirPushNotification ├── AirPushNotification.h ├── AirPushNotification.m ├── FlashRuntimeExtensions.h ├── NotifCenterDelegate.h └── NotifCenterDelegate.m ├── AirPushNotificationMac └── Info.plist ├── Podfile ├── Podfile.lock └── Pods ├── Manifest.lock ├── Pods.xcodeproj └── project.pbxproj └── Target Support Files └── Pods-AirPushNotification ├── Pods-AirPushNotification-acknowledgements.markdown ├── Pods-AirPushNotification-acknowledgements.plist ├── Pods-AirPushNotification-dummy.m ├── Pods-AirPushNotification-frameworks.sh ├── Pods-AirPushNotification-resources.sh ├── Pods-AirPushNotification.debug.xcconfig └── Pods-AirPushNotification.release.xcconfig /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | temp 3 | build.config 4 | 5 | # Flash Builder 6 | actionscript/bin 7 | .actionScriptProperties 8 | .flexLibProperties 9 | 10 | # Eclipse 11 | .settings 12 | .project 13 | 14 | # Android 15 | bin/AirPushNotification_multiMsg.ane 16 | android/bin 17 | android/gen 18 | android/lint.xml 19 | .classpath 20 | proguard-project.txt 21 | project.properties 22 | 23 | # Xcode 24 | xcuserdata 25 | ios/build 26 | 27 | # OS X 28 | Icon 29 | Thumbs.db 30 | .DS_Store 31 | 32 | # IntelliJ 33 | .idea 34 | *.iml 35 | android/lib/src/main/gen/ 36 | 37 | android/full_libs/ 38 | android/\.gradle/ 39 | 40 | android/lib/build/ 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Freshplanet (http://freshplanet.com | opensource@freshplanet.com) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Air Native Extension for Push Notifications (iOS + Android) 2 | ====================================== 3 | 4 | This is an [Air native extension](http://www.adobe.com/devnet/air/native-extensions-for-air.html) for sending push notifications on iOS and Android. It has been developed by [FreshPlanet](http://freshplanet.com) and is used in the game [SongPop](http://songpop.fm). 5 | 6 | 7 | Push Notifications 8 | --------- 9 | 10 | On iOS devices, this ANE uses Apple [Push Notification Services](https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html). On Android devices, it uses [Google Cloud Messaging (GCM)](http://developer.android.com/guide/google/gcm/index.html). 11 | 12 | 13 | Installation 14 | --------- 15 | 16 | If your app is iOS-only, you can directly use the binary located in the *bin* folder (AirPushNotification.ane). You should add it to your application project's Build Path and make sure to package it with your app (more information [here](http://help.adobe.com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html)). 17 | 18 | If your app supports Android, you need to compile the ANE with your own assets (status bar icon etc...). To do that, use the ant build script located in the *build* folder (build.xml): 19 | 20 | ```xml 21 | cd /path/to/the/ane/build 22 | mv example.build.config build.config 23 | # edit the build.config file to provide your machine-specific paths 24 | ant 25 | ``` 26 | 27 | You should also update your manifest with: 28 | 29 | ``` 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | ``` 63 | 64 | and replace INSERT.APP.ID.HERE by your application id ( tag in your manifest). 65 | 66 | 67 | Usage 68 | ----- 69 | 70 | ```actionscript 71 | 72 | // Register the device for a push notifications 73 | // GOOGLE_PROJECT_ID is necessary only on Android and is your project's ID on GCM. 74 | // On iOS, you can call the method with no parameter. 75 | PushNotification.getInstance().registerForPushNotification(GOOGLE_PROJECT_ID); 76 | 77 | // Register for events 78 | PushNotification.getInstance().addEventListener(PushNotificationEvent.PERMISSION_GIVEN_WITH_TOKEN_EVENT, onPushNotificationToken); 79 | PushNotification.getInstance().addEventListener(PushNotificationEvent.NOTIFICATION_RECEIVED_WHEN_IN_FOREGROUND_EVENT, onNotificationReceivedInForeground); 80 | PushNotification.getInstance().addEventListener( PushNotificationEvent.APP_BROUGHT_TO_FOREGROUND_FROM_NOTIFICATION_EVENT, onNotificationReceivedInBackground); 81 | PushNotification.getInstance().addListenerForStarterNotifications(onNotificationReceivedStartingTheApp); 82 | 83 | // Handle events 84 | function onPushNotificationToken(event:PushNotificationEvent):void 85 | { 86 | trace("My push token is: " + event.token); 87 | } 88 | // other event handlers also receive a PushNotificationEvent 89 | 90 | ``` 91 | 92 | Packaging final app for Android 93 | ------------------------------- 94 | 95 | When you build your final APK for Android, you need to update (patch) the AIRSDK you're using. 96 | First, make sure you download the latest build-tools (from the Android SDK manager). 97 | Then, patch your AIR SDK with the following command: 98 | `cp pathtoyourANDROIDSDK/build-tools/22.0.1/lib/dx.jar pathtoyourAIRSDK/lib/android/bin/dx.jar` 99 | 100 | 101 | Notes: 102 | * included binary has been compiled for 64-bit iOS support 103 | 104 | Authors 105 | ------ 106 | 107 | This ANE has been written by [Thibaut Crenn](https://github.com/titi-us). It belongs to [FreshPlanet Inc.](http://freshplanet.com) and is distributed under the [Apache Licence, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 108 | 109 | 110 | Join the FreshPlanet team - GAME DEVELOPMENT in NYC 111 | ------ 112 | 113 | We are expanding our mobile engineering teams. 114 | 115 | FreshPlanet is a NYC based mobile game development firm and we are looking for senior engineers to lead the development initiatives for one or more of our games/apps. We work in small teams (6-9) who have total product control. These teams consist of mobile engineers, UI/UX designers and product experts. 116 | 117 | 118 | Please contact Tom Cassidy (tcassidy@freshplanet.com) or apply at http://freshplanet.com/jobs/ 119 | -------------------------------------------------------------------------------- /actionscript/src/com/freshplanet/ane/AirPushNotification/PushNotificationCategoryActioniOS.as: -------------------------------------------------------------------------------- 1 | package com.freshplanet.ane.AirPushNotification { 2 | public class PushNotificationCategoryActioniOS { 3 | 4 | public var id:String; 5 | public var titleKey:String; 6 | 7 | public function PushNotificationCategoryActioniOS(id:String, titleKey:String) { 8 | this.id = id; 9 | this.titleKey = titleKey; 10 | } 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /actionscript/src/com/freshplanet/ane/AirPushNotification/PushNotificationCategoryiOS.as: -------------------------------------------------------------------------------- 1 | package com.freshplanet.ane.AirPushNotification { 2 | public class PushNotificationCategoryiOS { 3 | 4 | public var id:String; 5 | 6 | public var hiddenSummaryKey:String; 7 | public var hiddenSummaryKeyFile:String; 8 | 9 | public var summaryKey:String; 10 | public var summaryKeyFile:String; 11 | 12 | public var action:PushNotificationCategoryActioniOS; 13 | 14 | public function PushNotificationCategoryiOS( 15 | id:String, 16 | hiddenSummaryKey:String, 17 | hiddenSummaryKeyFile:String, 18 | summaryKey:String, 19 | summaryKeyFile:String, 20 | action:PushNotificationCategoryActioniOS 21 | ) { 22 | this.id = id; 23 | this.hiddenSummaryKey = hiddenSummaryKey; 24 | this.hiddenSummaryKeyFile = hiddenSummaryKeyFile; 25 | this.summaryKey = summaryKey; 26 | this.summaryKeyFile = summaryKeyFile; 27 | this.action = action; 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /actionscript/src/com/freshplanet/ane/AirPushNotification/PushNotificationEvent.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification { 16 | 17 | import flash.events.Event; 18 | 19 | /** 20 | * 21 | */ 22 | public class PushNotificationEvent extends Event { 23 | 24 | /** 25 | * 26 | */ 27 | public static const PERMISSION_GIVEN_WITH_TOKEN_EVENT : String = "permissiongivenwithtokenevent"; 28 | 29 | /** 30 | * 31 | */ 32 | public static const PERMISSION_REFUSED_EVENT : String = "permissionRefusedEvent"; 33 | 34 | /** 35 | * 36 | */ 37 | public static const COMING_FROM_NOTIFICATION_EVENT : String = "comingFromNotificationEvent"; 38 | 39 | /** 40 | * App is launched (for the first time) when clicking on the push notification 41 | */ 42 | public static const APP_STARTING_FROM_NOTIFICATION_EVENT : String = "startingFromNotificationEvent"; 43 | 44 | /** 45 | * App was in background when clicking on the push notification 46 | */ 47 | public static const APP_BROUGHT_TO_FOREGROUND_FROM_NOTIFICATION_EVENT : String = "BroughtToForegroundFromNotificationEvent"; 48 | 49 | /** App was in background and awoken by iOS when receiving the push notification (background fetch on iOS 7+) */ 50 | public static const APP_STARTED_IN_BACKGROUND_FROM_NOTIFICATION_EVENT : String = "StartedInBackgroundFromNotificationEvent"; 51 | 52 | /** 53 | * App was in foreground when receiving push notification 54 | */ 55 | public static const NOTIFICATION_RECEIVED_WHEN_IN_FOREGROUND_EVENT : String = "NotificationReceivedWhenInForegroundEvent"; 56 | 57 | /** 58 | * Not available on earlier OS versions 59 | */ 60 | public static const NOTIFICATION_SETTINGS_ENABLED: String = "notificationSettingsEnabled"; 61 | public static const NOTIFICATION_SETTINGS_DISABLED: String = "notificationSettingsDisabled"; 62 | 63 | public static const GET_NOTIFICATIONS_ENABLED_RESULT: String = "getNotificationsEnabledResult"; 64 | 65 | public static const OPEN_APP_NOTIFICATION_SETTINGS : String = "openAppNotificationSettings"; 66 | public static const LOG_ISSUE : String = "logIssue"; 67 | 68 | public var token:String = null; 69 | public var errorCode:String = null; 70 | public var errorMessage:String = null; 71 | public var parameters:Object = null; 72 | public var value:Object = null; 73 | 74 | public function PushNotificationEvent(type:String, value:Object = null) { 75 | super(type, false, false); 76 | this.value = value; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /actionscript/src/com/freshplanet/ane/AirPushNotification/PushNotificationImportance.as: -------------------------------------------------------------------------------- 1 | package com.freshplanet.ane.AirPushNotification { 2 | public class PushNotificationImportance { 3 | public static var IMPORTANCE_HIGHT:int = 4; 4 | public static var IMPORTANCE_DEFAULT:int = 3; 5 | public static var IMPORTANCE_LOW:int = 2; 6 | public static var IMPORTANCE_MAX:int = 5; 7 | public static var IMPORTANCE_MIN:int = 1; 8 | public static var IMPORTANCE_NONE:int = 0; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | 4 | repositories { 5 | google() 6 | jcenter() 7 | maven { 8 | url "https://maven.google.com" 9 | } 10 | 11 | 12 | } 13 | 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:3.5.3' 16 | 17 | 18 | classpath 'com.google.firebase:firebase-messaging:17.3.4' 19 | classpath 'com.google.firebase:firebase-iid:17.0.4' 20 | } 21 | 22 | 23 | } 24 | 25 | allprojects { 26 | repositories { 27 | google() 28 | jcenter() 29 | maven { 30 | url "https://maven.google.com" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /android/example.local.properties: -------------------------------------------------------------------------------- 1 | sdk.dir=/path/to/android/sdk -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.useAndroidX=true 20 | android.enableJetifier=true 21 | -------------------------------------------------------------------------------- /android/gradle/wrapper.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | def wrapperUpdateTask = { name, label -> 18 | def wrapperTaskName = "${name}Wrapper" 19 | def configureWrapperTaskName = "configure${wrapperTaskName.capitalize()}" 20 | 21 | task "$configureWrapperTaskName" { 22 | doLast { 23 | configure(tasks."$wrapperTaskName") { 24 | def version = new groovy.json.JsonSlurper().parseText(new URL("https://services.gradle.org/versions/$label").text) 25 | if (version.empty) { 26 | throw new GradleException("Cannot update wrapper to '${label}' version as there is currently no version of that label") 27 | } 28 | println "updating wrapper to $label version: $version.version (downloadUrl: $version.downloadUrl)" 29 | distributionUrl version.downloadUrl 30 | } 31 | } 32 | } 33 | 34 | task "${wrapperTaskName}"(type: Wrapper, dependsOn: configureWrapperTaskName) { 35 | group = "wrapper" 36 | } 37 | } 38 | 39 | tasks.withType(Wrapper) { 40 | def jvmOpts = "-Xmx1024m -Dfile.encoding=UTF-8" 41 | inputs.property("jvmOpts", jvmOpts) 42 | doLast { 43 | def optsEnvVar = "DEFAULT_JVM_OPTS" 44 | scriptFile.write scriptFile.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"") 45 | batchScript.write batchScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts") 46 | } 47 | } 48 | wrapperUpdateTask "nightly", "nightly" 49 | wrapperUpdateTask "rc", "release-candidate" 50 | wrapperUpdateTask "current", "current" 51 | 52 | if (useIncomingDistributions) { 53 | task incomingDistributionsWrapper(type: Wrapper) { 54 | distributionUrl = incomingAllDistribution.toURI().toURL() 55 | group = 'wrapper' 56 | distributionBase = Wrapper.PathBase.PROJECT 57 | archiveBase = Wrapper.PathBase.PROJECT 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 28 19:18:21 CET 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /android/lib/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | apply plugin: 'com.android.library' 3 | 4 | dependencies { 5 | compileOnly files('libs/amazon-device-messaging-1.1.0.jar') 6 | implementation files('libs/FlashRuntimeExtensions.jar') 7 | implementation 'com.google.firebase:firebase-messaging:23.1.2' 8 | } 9 | 10 | android { 11 | 12 | useLibrary 'org.apache.http.legacy' 13 | 14 | compileSdkVersion 33 15 | buildToolsVersion '33.0.2' 16 | 17 | defaultConfig { 18 | minSdkVersion 16 19 | targetSdkVersion 33 20 | } 21 | 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_1_8 24 | targetCompatibility JavaVersion.VERSION_1_8 25 | } 26 | } 27 | 28 | task copyDependencies(type: Copy) { 29 | configurations.implementation.setCanBeResolved(true) 30 | from configurations.implementation 31 | into 'dependencies' 32 | } 33 | 34 | -------------------------------------------------------------------------------- /android/lib/libs/FlashRuntimeExtensions.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/libs/FlashRuntimeExtensions.jar -------------------------------------------------------------------------------- /android/lib/libs/amazon-device-messaging-1.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/libs/amazon-device-messaging-1.1.0.jar -------------------------------------------------------------------------------- /android/lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/distriqt/extension/util/Resources.java: -------------------------------------------------------------------------------- 1 | /** 2 | * __ __ __ 3 | * ____/ /_ ____/ /______ _ ___ / /_ 4 | * / __ / / ___/ __/ ___/ / __ `/ __/ 5 | * / /_/ / (__ ) / / / / / /_/ / / 6 | * \__,_/_/____/_/ /_/ /_/\__, /_/ 7 | * / / 8 | * \/ 9 | * http://distriqt.com 10 | * 11 | * @file Resources.java 12 | * @brief 13 | * @author Michael Archbold 14 | * @created Apr 16, 2012 15 | * @updated $Date:$ 16 | * @copyright http://distriqt.com/copyright/license.txt 17 | * 18 | */ 19 | package com.distriqt.extension.util; 20 | 21 | import android.util.Log; 22 | import java.lang.reflect.Field; 23 | 24 | public class Resources 25 | { 26 | 27 | /** 28 | * Retrieves an Android resource id for the given package, class and asset name. 29 | * 30 | * @param packageName This should be the package of your application from something like Context.getPackageName() 31 | * @param className The class of the resource, eg "drawable" 32 | * @param name The name of the resource, eg "icon" 33 | * @return The Android resource id of the resource or -1 if it wasn't found 34 | */ 35 | public static int getResourseIdByName(String packageName, String className, String name) 36 | { 37 | int id = 0; 38 | try 39 | { 40 | for (int i = 0; i < Class.forName(packageName + ".R").getClasses().length; i++) 41 | { 42 | if(Class.forName(packageName + ".R").getClasses()[i].getName().split("\\$")[1].equals(className)) 43 | { 44 | if(Class.forName(packageName + ".R").getClasses()[i] != null) 45 | id = Class.forName(packageName + ".R").getClasses()[i].getField(name).getInt(Class.forName(packageName + ".R").getClasses()[i]); 46 | break; 47 | } 48 | } 49 | } 50 | catch (Exception e) 51 | { 52 | return -1; 53 | } 54 | return id; 55 | } 56 | 57 | 58 | 59 | public static void listResources( String packageName ) 60 | { 61 | try 62 | { 63 | for (int i = 0; i < Class.forName(packageName + ".R").getClasses().length; i++) 64 | { 65 | Field [] fields = Class.forName(packageName + ".R").getClasses()[i].getFields(); 66 | for (int j = 0; j < fields.length; j++) 67 | { 68 | Log.d("Resources", Class.forName(packageName + ".R").getClasses()[i].getName()+"::"+fields[j].getName() ); 69 | } 70 | } 71 | } 72 | catch (Exception e) 73 | { 74 | e.printStackTrace(); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/ADMHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * [ADMHelper.java] 3 | * 4 | * (c) 2019, Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | */ 6 | package com.freshplanet.ane.AirPushNotification; 7 | 8 | import android.app.Notification; 9 | import android.app.NotificationManager; 10 | import android.app.PendingIntent; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | import android.os.Build; 14 | 15 | /** 16 | * The ADMHelper class ia a helper class. 17 | * 18 | * @version Revision: 1, Date: 11/20/2019 19 | */ 20 | public class ADMHelper { 21 | 22 | public static final String ADM_CLASSNAME = "com.amazon.device.messaging.ADM"; 23 | public static final String ADMV2_HANDLER = "com.amazon.device.messaging.ADMMessageHandlerJobBase"; 24 | public static final int JOB_ID = 1324124; 25 | public static final String CHANNEL_ID = "notification_channel"; 26 | public static final String CHANNEL_NAME = "Notification Channel"; 27 | 28 | public static final boolean IS_ADM_AVAILABLE; 29 | public static final boolean IS_ADM_V2; 30 | 31 | private static boolean isClassAvailable(final String className) { 32 | try { 33 | Class.forName(className); 34 | return true; 35 | } catch (ClassNotFoundException e) { 36 | return false; 37 | } 38 | } 39 | 40 | static { 41 | IS_ADM_AVAILABLE = isClassAvailable(ADM_CLASSNAME); 42 | IS_ADM_V2 = IS_ADM_AVAILABLE ? isClassAvailable(ADMV2_HANDLER) : false; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CancelAllLocalNotificationsFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import com.adobe.fre.FREContext; 18 | import com.adobe.fre.FREFunction; 19 | import com.adobe.fre.FREObject; 20 | 21 | /** 22 | * Created by peter on 5/15/15. 23 | */ 24 | public class CancelAllLocalNotificationsFunction implements FREFunction { 25 | 26 | @Override 27 | public FREObject call(FREContext freContext, FREObject[] freObjects) { 28 | //TODO implement this; may need to store ids somewhere 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CancelLocalNotificationFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.AlarmManager; 18 | import android.app.PendingIntent; 19 | import android.content.Context; 20 | import android.content.Intent; 21 | 22 | import com.adobe.fre.FREContext; 23 | import com.adobe.fre.FREFunction; 24 | import com.adobe.fre.FREInvalidObjectException; 25 | import com.adobe.fre.FREObject; 26 | import com.adobe.fre.FRETypeMismatchException; 27 | import com.adobe.fre.FREWrongThreadException; 28 | 29 | public class CancelLocalNotificationFunction implements FREFunction { 30 | 31 | public CancelLocalNotificationFunction() { 32 | // TODO Auto-generated constructor stub 33 | } 34 | 35 | @Override 36 | public FREObject call(FREContext arg0, FREObject[] arg1) { 37 | // TODO Auto-generated method stub 38 | 39 | Context appContext = arg0.getActivity().getApplicationContext(); 40 | Intent intent = new Intent(appContext, LocalBroadcastReceiver.class); 41 | 42 | int notificationId = 0; 43 | 44 | try { 45 | notificationId = arg1[0].getAsInt(); 46 | } catch (IllegalStateException e) { 47 | e.printStackTrace(); 48 | } catch (FRETypeMismatchException e) { 49 | e.printStackTrace(); 50 | } catch (FREInvalidObjectException e) { 51 | e.printStackTrace(); 52 | } catch (FREWrongThreadException e) { 53 | e.printStackTrace(); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | 58 | PendingIntent sender; 59 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { 60 | sender = PendingIntent.getBroadcast(appContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); 61 | } 62 | else { 63 | sender = PendingIntent.getBroadcast(appContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); 64 | } 65 | // Get the AlarmManager service 66 | AlarmManager am = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); 67 | am.cancel(sender); 68 | 69 | 70 | 71 | 72 | return null; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CheckNotificationChannelEnabled.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.NotificationChannel; 18 | import android.app.NotificationManager; 19 | import android.content.Context; 20 | import android.os.Build; 21 | import android.text.TextUtils; 22 | 23 | import androidx.core.app.NotificationManagerCompat; 24 | 25 | import com.adobe.fre.FREContext; 26 | import com.adobe.fre.FREFunction; 27 | import com.adobe.fre.FREInvalidObjectException; 28 | import com.adobe.fre.FREObject; 29 | import com.adobe.fre.FRETypeMismatchException; 30 | import com.adobe.fre.FREWrongThreadException; 31 | 32 | public class CheckNotificationChannelEnabled implements FREFunction { 33 | 34 | @Override 35 | public FREObject call(FREContext arg0, FREObject[] arg1) { 36 | 37 | 38 | if (arg1.length > 0) 39 | { 40 | String channelId = null; 41 | try { 42 | channelId = arg1[0].getAsString(); 43 | } catch (IllegalStateException e) { 44 | e.printStackTrace(); 45 | } catch (FRETypeMismatchException e) { 46 | e.printStackTrace(); 47 | } catch (FREInvalidObjectException e) { 48 | e.printStackTrace(); 49 | } catch (FREWrongThreadException e) { 50 | e.printStackTrace(); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | 55 | Context appContext = arg0.getActivity().getApplicationContext(); 56 | 57 | 58 | 59 | boolean isEnabled = true; 60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 61 | if(!TextUtils.isEmpty(channelId)) { 62 | NotificationManager manager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); 63 | NotificationChannel channel = manager.getNotificationChannel(channelId); 64 | isEnabled = channel.getImportance() != NotificationManager.IMPORTANCE_NONE; 65 | } 66 | else 67 | isEnabled = false; 68 | } else { 69 | isEnabled = NotificationManagerCompat.from(appContext).areNotificationsEnabled(); 70 | } 71 | 72 | try { 73 | return FREObject.newObject(isEnabled); 74 | } 75 | catch (FREWrongThreadException e) { 76 | Extension.logToAIR("unable to return value for channel enabled"); 77 | } 78 | 79 | } 80 | 81 | return null; 82 | } 83 | 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CreateNotificationChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.Activity; 18 | import android.app.NotificationChannel; 19 | import android.app.NotificationManager; 20 | import android.content.Context; 21 | import android.content.SharedPreferences; 22 | import android.os.Build; 23 | 24 | import com.adobe.fre.FREContext; 25 | import com.adobe.fre.FREFunction; 26 | import com.adobe.fre.FREInvalidObjectException; 27 | import com.adobe.fre.FREObject; 28 | import com.adobe.fre.FRETypeMismatchException; 29 | import com.adobe.fre.FREWrongThreadException; 30 | 31 | public class CreateNotificationChannel implements FREFunction { 32 | 33 | @Override 34 | public FREObject call(FREContext arg0, FREObject[] arg1) { 35 | 36 | Extension.logToAIR("start storing notif tracking"); 37 | 38 | 39 | 40 | 41 | try { 42 | 43 | String channelId = arg1[0].getAsString(); 44 | String channelName = arg1[1].getAsString(); 45 | int importance = arg1[2].getAsInt(); 46 | boolean enableLights = arg1[3].getAsBool(); 47 | boolean enableVibration = arg1[4].getAsBool(); 48 | 49 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ 50 | Context appContext = arg0.getActivity().getApplicationContext(); 51 | NotificationManager notifManager = (NotificationManager)appContext.getSystemService(Context.NOTIFICATION_SERVICE); 52 | NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName ,importance); 53 | notificationChannel.enableLights(enableLights); 54 | notificationChannel.enableVibration(enableVibration); 55 | notifManager.createNotificationChannel(notificationChannel); 56 | } 57 | else { 58 | Extension.logToAIR("Notification channels available only on Android API >= 26"); 59 | } 60 | 61 | } catch (IllegalStateException e) { 62 | e.printStackTrace(); 63 | } catch (FRETypeMismatchException e) { 64 | e.printStackTrace(); 65 | } catch (FREInvalidObjectException e) { 66 | e.printStackTrace(); 67 | } catch (FREWrongThreadException e) { 68 | e.printStackTrace(); 69 | } catch (NullPointerException e) { 70 | e.printStackTrace(); 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | 75 | 76 | 77 | return null; 78 | } 79 | 80 | private void storeUrl(Activity act, String url) { 81 | 82 | // We need an Editor object to make preference changes. 83 | // All objects are from android.context.Context 84 | SharedPreferences settings = act.getSharedPreferences(Extension.PREFS_NAME, Context.MODE_PRIVATE); 85 | SharedPreferences.Editor editor = settings.edit(); 86 | editor.putString(Extension.PREFS_KEY, url); 87 | 88 | // Commit the edits! 89 | editor.commit(); 90 | 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CreateNotificationTask.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | import android.content.Intent; 19 | import android.graphics.Bitmap; 20 | import android.os.AsyncTask; 21 | import android.os.Bundle; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | public class CreateNotificationTask extends AsyncTask 27 | { 28 | 29 | private Context _context; 30 | private Map _messageData; 31 | private Bitmap _picture; 32 | 33 | public CreateNotificationTask(Context context, Intent intent) 34 | { 35 | super(); 36 | _context = context; 37 | Map messageData = new HashMap<>(); 38 | Bundle bundle = intent.getExtras(); 39 | for (String key : bundle.keySet()) 40 | { 41 | String convertedToString = "" + bundle.get(key); 42 | messageData.put(key, convertedToString); 43 | } 44 | 45 | _messageData = messageData; 46 | } 47 | 48 | @Override 49 | protected Boolean doInBackground(Void... params) 50 | { 51 | // Try to download the picture 52 | try 53 | { 54 | _picture = FCMMessagingService.downloadImage(_context, _messageData); 55 | return _picture != null; 56 | } 57 | catch (Exception e) 58 | { 59 | e.printStackTrace(); 60 | return false; 61 | } 62 | } 63 | 64 | @Override 65 | protected void onPostExecute(Boolean downloadSuccess) 66 | { 67 | if (_context == null || _messageData == null) 68 | { 69 | Extension.logToAIR("Couldn't create push notification: _context or _intent was null (CreateNotificationTask.onPostExecute)"); 70 | return; 71 | } 72 | FCMMessagingService.displayMessage(_context, _picture, _messageData); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/CreateNotificationTask_multiMsg.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.freshplanet.ane.AirPushNotification; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.net.HttpURLConnection; 21 | import java.net.URL; 22 | 23 | import com.distriqt.extension.util.Resources; 24 | 25 | import android.annotation.TargetApi; 26 | import android.app.Notification; 27 | import android.app.NotificationManager; 28 | import android.content.Context; 29 | import android.graphics.Bitmap; 30 | import android.graphics.BitmapFactory; 31 | import android.os.AsyncTask; 32 | import android.os.Build; 33 | import android.widget.RemoteViews; 34 | 35 | public class CreateNotificationTask_multiMsg extends AsyncTask 36 | { 37 | 38 | // 39 | // private int _notifyId; 40 | // private int _customLayoutImageContainer; 41 | private Notification _notification; 42 | private NotificationManager _nm; 43 | private Context _context; 44 | private String _imagecontainer; 45 | private RemoteViews _remoteviews; 46 | private Bitmap _bitmap; 47 | 48 | public CreateNotificationTask_multiMsg() 49 | { 50 | super(); 51 | } 52 | 53 | public void setParams(Context context, RemoteViews remoteviews, String imagecontainer, Notification notification, NotificationManager nm) 54 | { 55 | _context = context; 56 | _remoteviews = remoteviews; 57 | _imagecontainer = imagecontainer; 58 | _notification = notification; 59 | _nm = nm; 60 | } 61 | 62 | @Override 63 | protected Long doInBackground(URL... urls) 64 | { 65 | try 66 | { 67 | HttpURLConnection connection = (HttpURLConnection) urls[0].openConnection(); 68 | connection.setDoInput(true); 69 | connection.connect(); 70 | InputStream input = connection.getInputStream(); 71 | _bitmap = BitmapFactory.decodeStream(input); 72 | } catch (IOException e) 73 | { 74 | e.printStackTrace(); 75 | } 76 | return null; 77 | } 78 | 79 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 80 | @Override 81 | protected void onPostExecute(Long result) 82 | { 83 | _remoteviews.setImageViewBitmap(Resources.getResourseIdByName(_context.getPackageName(), "id", _imagecontainer), _bitmap); 84 | 85 | _notification.bigContentView = _remoteviews; 86 | _nm.notify(0, _notification); 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/Extension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | import android.content.Intent; 19 | import android.content.SharedPreferences; 20 | import android.os.Bundle; 21 | import android.util.Log; 22 | 23 | import com.adobe.fre.FREContext; 24 | import com.adobe.fre.FREExtension; 25 | import com.amazon.device.messaging.ADM; 26 | 27 | import org.json.JSONException; 28 | import org.json.JSONObject; 29 | 30 | import java.io.UnsupportedEncodingException; 31 | import java.net.URLEncoder; 32 | import java.util.Map; 33 | import java.util.concurrent.atomic.AtomicInteger; 34 | 35 | public class Extension implements FREExtension { 36 | 37 | private static String TAG = "AirPushNotification"; 38 | 39 | public static final String PREFS_NAME = "UrlPrefFile"; 40 | public static final String PREFS_KEY = "trackUrl"; 41 | 42 | public static final String PREFS_NOTIFICATION_NAME = "notifIdsFile"; 43 | public static final String PREFS_NOTIFICATION_ID = "notificationId"; 44 | 45 | private static AtomicInteger atomicInt; 46 | public static ExtensionContext context; 47 | public static ADM adm = null; 48 | 49 | public static boolean isInForeground = false; 50 | 51 | 52 | public static int getNotificationID(Context context) { 53 | 54 | SharedPreferences settings = context.getSharedPreferences(Extension.PREFS_NOTIFICATION_NAME, Context.MODE_PRIVATE); 55 | if(atomicInt == null) { 56 | String notificationIdString = settings.getString(Extension.PREFS_NOTIFICATION_ID, null); 57 | if(notificationIdString != null) { 58 | atomicInt = new AtomicInteger(Integer.valueOf(notificationIdString)); 59 | } 60 | else{ 61 | atomicInt = new AtomicInteger(1); 62 | } 63 | 64 | } 65 | 66 | int id = atomicInt.incrementAndGet(); 67 | SharedPreferences.Editor editor = settings.edit(); 68 | if(id > 1000000) { // do not grow too much 69 | id = 0; 70 | } 71 | editor.putString(Extension.PREFS_NOTIFICATION_ID, Integer.toString((id+1))); 72 | editor.commit(); 73 | return id; 74 | } 75 | 76 | public static int getSummaryID(Context context, String groupId) { 77 | 78 | SharedPreferences settings = context.getSharedPreferences(Extension.PREFS_NOTIFICATION_NAME, Context.MODE_PRIVATE); 79 | // check saved notification ID based on groupId 80 | String summaryIdString = settings.getString(groupId, null); 81 | 82 | // if it exists - return that one 83 | if(summaryIdString != null) { 84 | return Integer.valueOf(summaryIdString); 85 | } 86 | // if none exists - get new one and save it 87 | int newID = getNotificationID(context); 88 | SharedPreferences.Editor editor = settings.edit(); 89 | editor.putString(groupId, Integer.toString((newID))); 90 | editor.commit(); 91 | 92 | return newID; 93 | } 94 | 95 | public static Boolean isSummaryID(Context context, String groupId, int notificationId) { 96 | 97 | SharedPreferences settings = context.getSharedPreferences(Extension.PREFS_NOTIFICATION_NAME, Context.MODE_PRIVATE); 98 | // check saved notification ID based on groupId 99 | String summaryIdString = settings.getString(groupId, null); 100 | return summaryIdString != null && Integer.valueOf(summaryIdString) == notificationId; 101 | } 102 | 103 | public FREContext createContext(String extId) 104 | { 105 | context = new ExtensionContext(); 106 | return context; 107 | } 108 | 109 | public void dispose() 110 | { 111 | context = null; 112 | } 113 | 114 | public void initialize() { 115 | 116 | } 117 | 118 | public static void logToAIR(String message) 119 | { 120 | Log.d(TAG, message); 121 | 122 | if (context != null) 123 | { 124 | try { 125 | context.dispatchStatusEventAsync("LOGGING", message); 126 | } catch (IllegalStateException e) { 127 | Log.e(TAG, "logToAIR: couldn't dispatch AS3 logging event", e); 128 | } 129 | } 130 | } 131 | 132 | public static String getParametersFromMessage(Map messageData) 133 | { 134 | JSONObject paramsJson = new JSONObject(); 135 | String parameters = messageData.get("parameters"); 136 | try 137 | { 138 | for (Map.Entry entry: messageData.entrySet()) 139 | { 140 | paramsJson.put(entry.getKey(), entry.getValue()); 141 | } 142 | 143 | if(parameters != null) 144 | { 145 | paramsJson.put("parameters", new JSONObject(parameters)); 146 | } 147 | } 148 | catch (JSONException e) 149 | { 150 | e.printStackTrace(); 151 | } 152 | 153 | return paramsJson.toString(); 154 | } 155 | 156 | public static String getParametersFromIntent(Intent intent) 157 | { 158 | JSONObject paramsJson = new JSONObject(); 159 | Bundle bundle = intent.getExtras(); 160 | String parameters = intent.getStringExtra("parameters"); 161 | try 162 | { 163 | for (String key : bundle.keySet()) 164 | { 165 | String convertedToString = "" + bundle.get(key); 166 | paramsJson.put(key, convertedToString); 167 | } 168 | 169 | if(parameters != null) 170 | { 171 | paramsJson.put("parameters", new JSONObject(parameters)); 172 | } 173 | } 174 | catch (JSONException e) 175 | { 176 | e.printStackTrace(); 177 | } 178 | 179 | return paramsJson.toString(); 180 | } 181 | 182 | 183 | public static void trackNotification(Context context, Map messageData) 184 | { 185 | // retrieve stored url 186 | SharedPreferences settings = context.getSharedPreferences(Extension.PREFS_NAME, Context.MODE_PRIVATE); 187 | String trackingUrl = settings.getString(Extension.PREFS_KEY, null); 188 | if (trackingUrl != null) 189 | { 190 | String notifTrackingType = messageData.get("type"); 191 | String notifSender = messageData.get("sender"); 192 | String category = messageData.get("android_channel_id"); 193 | String trackingId = messageData.get("trackingId"); 194 | 195 | String linkParam = "/?source_type=notif&source_ref="+notifTrackingType; 196 | if (notifSender != null) 197 | { 198 | linkParam += "&source_userId="+notifSender; 199 | } 200 | 201 | if(Extension.isInForeground) { 202 | linkParam += "&appState=active"; 203 | } 204 | else { 205 | linkParam += "&appState=inactive"; 206 | } 207 | 208 | if(category != null) { 209 | linkParam += "&category="+category; 210 | } 211 | 212 | if(trackingId != null) { 213 | linkParam += "&trackingId="+trackingId; 214 | } 215 | 216 | try { 217 | trackingUrl += "&link="+ URLEncoder.encode(linkParam, "UTF-8"); 218 | 219 | } catch (UnsupportedEncodingException e) { 220 | e.printStackTrace(); 221 | return; 222 | } catch (Exception e) { 223 | e.printStackTrace(); 224 | return; 225 | } 226 | 227 | PingUrlTask task = new PingUrlTask(); 228 | task.execute(trackingUrl); 229 | 230 | } else 231 | { 232 | Extension.logToAIR("couldn't find stored tracking url"); 233 | } 234 | } 235 | } -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/ExtensionContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | import android.content.Intent; 19 | import android.util.Log; 20 | import android.os.Build; 21 | 22 | import androidx.annotation.NonNull; 23 | import androidx.core.app.NotificationManagerCompat; 24 | 25 | import com.adobe.fre.FREContext; 26 | import com.adobe.fre.FREFunction; 27 | import com.adobe.fre.FREObject; 28 | import com.amazon.device.messaging.ADM; 29 | import com.google.android.gms.tasks.OnCompleteListener; 30 | import com.google.android.gms.tasks.Task; 31 | import com.google.firebase.messaging.FirebaseMessaging; 32 | 33 | import java.util.HashMap; 34 | import java.util.Map; 35 | 36 | public class ExtensionContext extends FREContext { 37 | 38 | public static FCMMessagingService messagingService; 39 | 40 | public ExtensionContext() { 41 | } 42 | 43 | @Override 44 | public void dispose() { 45 | Extension.context = null; 46 | } 47 | 48 | @Override 49 | public Map getFunctions() { 50 | 51 | Map functionMap = new HashMap(); 52 | 53 | functionMap.put("registerPush", regPushFunc); 54 | functionMap.put("setBadgeNb", new SetBadgeValueFunction()); 55 | functionMap.put("sendLocalNotification", new LocalNotificationFunction()); 56 | functionMap.put("setIsAppInForeground", new SetIsAppInForegroundFunction()); 57 | functionMap.put("fetchStarterNotification", new FetchStarterNotificationFunction()); 58 | functionMap.put("cancelLocalNotification", new CancelLocalNotificationFunction()); 59 | functionMap.put("cancelAllLocalNotifications", new CancelLocalNotificationFunction()); 60 | functionMap.put("getNotificationsEnabled", new GetNotificationsEnabledFunction()); 61 | functionMap.put("openDeviceNotificationSettings", new GoToNotifSettingsFunction()); 62 | functionMap.put("getCanSendUserToSettings", new GetCanSendUserToSettings()); 63 | functionMap.put("storeNotifTrackingInfo", new StoreNotifTrackingInfo()); 64 | functionMap.put("createNotificationChannel", new CreateNotificationChannel()); 65 | functionMap.put("checkNotificationChannelEnabled", new CheckNotificationChannelEnabled()); 66 | 67 | return functionMap; 68 | } 69 | 70 | private final FREFunction regPushFunc = new FREFunction() { 71 | @Override 72 | public FREObject call(FREContext freContext, FREObject[] freObjects) { 73 | if(ADMHelper.IS_ADM_AVAILABLE) { 74 | return callAmazon(freContext, freObjects); 75 | } 76 | return callAndroid(freContext, freObjects); 77 | } 78 | 79 | private FREObject callAndroid(FREContext context, FREObject[] args) { 80 | try { 81 | 82 | Context appContext = context.getActivity().getApplicationContext(); 83 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { 84 | Intent intent = new Intent(appContext, NotificationPermissionActivity.class); 85 | context.getActivity().startActivity(intent); 86 | } 87 | if(NotificationManagerCompat.from(appContext).areNotificationsEnabled()) { 88 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_SETTINGS_ENABLED", ""); 89 | } 90 | else { 91 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_SETTINGS_DISABLED", ""); 92 | } 93 | 94 | FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() { 95 | @Override 96 | public void onComplete(@NonNull Task task) { 97 | if (!task.isSuccessful()) { 98 | Exception e = task.getException(); 99 | Log.w("firebase", "getToken failed", e); 100 | Extension.context.dispatchStatusEventAsync("TOKEN_FAIL", e.getMessage()); 101 | return; 102 | } 103 | // Get new Instance ID token 104 | 105 | 106 | String token = task.getResult(); 107 | if (token != null) { 108 | Extension.context.dispatchStatusEventAsync("TOKEN_SUCCESS", token); 109 | } else { 110 | Extension.context.dispatchStatusEventAsync("TOKEN_FAIL", "NULL_TOKEN"); 111 | } 112 | } 113 | }); 114 | 115 | } catch (Exception e) { 116 | Log.e("firebase", "error", e); 117 | } 118 | return null; 119 | } 120 | 121 | private FREObject callAmazon(FREContext context, FREObject[] args) { 122 | 123 | Extension.logToAIR("ADM is available computed " + ADMHelper.IS_ADM_AVAILABLE); 124 | 125 | if (ADMHelper.IS_ADM_AVAILABLE) { 126 | 127 | Extension.logToAIR("ADMAvailable"); 128 | 129 | try { 130 | Extension.adm = new ADM(context.getActivity()); 131 | } catch (Exception e) { 132 | Extension.logToAIR( "error creating ADM error localizes " + e.getLocalizedMessage()); 133 | e.printStackTrace(); 134 | return null; 135 | } 136 | 137 | Extension.logToAIR( "ADM created"); 138 | 139 | String token = Extension.adm.getRegistrationId(); 140 | 141 | Extension.logToAIR( "Got token registration"); 142 | 143 | if (token == null) 144 | { 145 | Extension.logToAIR( "ADM start registering"); 146 | Extension.adm.startRegister(); 147 | } else 148 | { 149 | Extension.logToAIR( "ADM token already there: "+token); 150 | Extension.context.dispatchStatusEventAsync("TOKEN_SUCCESS", token); 151 | } 152 | 153 | } else { 154 | Extension.logToAIR( "ADM not available"); 155 | } 156 | 157 | Extension.logToAIR( "return"); 158 | 159 | 160 | return null; 161 | } 162 | }; 163 | } -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/FPADMMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.freshplanet.ane.AirPushNotification; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | import com.amazon.device.messaging.ADMMessageHandlerBase; 7 | 8 | public class FPADMMessageHandler extends ADMMessageHandlerBase { 9 | 10 | public FPADMMessageHandler() { 11 | super(FPADMMessageHandler.class.getName()); 12 | } 13 | 14 | public FPADMMessageHandler(final String className) { 15 | super(className); 16 | } 17 | 18 | 19 | @Override 20 | protected void onMessage(Intent intent) { 21 | 22 | // Extract message content from set of extras from 23 | // com.amazon.device.messaging.intent.RECEIVE intent 24 | 25 | Extension.logToAIR("on message"); 26 | 27 | 28 | try 29 | { 30 | String params = Extension.getParametersFromIntent(intent); 31 | 32 | Context context = getApplicationContext(); 33 | 34 | Extension.logToAIR("Received push notification with parameters: " + params); 35 | 36 | // Build the notification if the app is not in foreground, otherwise just dispatch an event 37 | if (!Extension.isInForeground) 38 | { 39 | 40 | new CreateNotificationTask(context, intent).execute(); 41 | 42 | } 43 | else if (Extension.context != null) 44 | { 45 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_RECEIVED_WHEN_IN_FOREGROUND", params); 46 | } 47 | } 48 | catch (Exception e) 49 | { 50 | e.printStackTrace(); 51 | } 52 | 53 | } 54 | 55 | @Override 56 | protected void onRegistered(String token) { 57 | 58 | Extension.logToAIR("Registered successfully with token: " + token); 59 | if (Extension.context == null) return; 60 | 61 | Extension.context.dispatchStatusEventAsync("TOKEN_SUCCESS", token); 62 | } 63 | 64 | @Override 65 | protected void onRegistrationError(String errorId) { 66 | 67 | Extension.logToAIR("Error registering " + errorId); 68 | Extension.context.dispatchStatusEventAsync("TOKEN_FAIL", errorId); 69 | } 70 | 71 | @Override 72 | protected void onUnregistered(String token) { 73 | 74 | Extension.logToAIR("Unregistered successfully"); 75 | Extension.context.dispatchStatusEventAsync("UNREGISTERED", token); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/FPADMMessageHandlerJobBase.java: -------------------------------------------------------------------------------- 1 | package com.freshplanet.ane.AirPushNotification; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | import com.amazon.device.messaging.ADMMessageHandlerBase; 7 | import com.amazon.device.messaging.ADMMessageHandlerJobBase; 8 | 9 | public class FPADMMessageHandlerJobBase extends ADMMessageHandlerJobBase { 10 | 11 | public FPADMMessageHandlerJobBase() 12 | { 13 | super(); 14 | } 15 | 16 | @Override 17 | protected void onMessage(final Context context, final Intent intent) { 18 | 19 | // Extract message content from set of extras from 20 | // com.amazon.device.messaging.intent.RECEIVE intent 21 | 22 | Extension.logToAIR("on message"); 23 | 24 | 25 | try 26 | { 27 | String params = Extension.getParametersFromIntent(intent); 28 | 29 | 30 | Extension.logToAIR("Received push notification with parameters: " + params); 31 | 32 | // Build the notification if the app is not in foreground, otherwise just dispatch an event 33 | if (!Extension.isInForeground) 34 | { 35 | 36 | new CreateNotificationTask(context, intent).execute(); 37 | 38 | } 39 | else if (Extension.context != null) 40 | { 41 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_RECEIVED_WHEN_IN_FOREGROUND", params); 42 | } 43 | } 44 | catch (Exception e) 45 | { 46 | e.printStackTrace(); 47 | } 48 | 49 | } 50 | 51 | @Override 52 | protected void onRegistered(final Context context, final String registrationId) { 53 | 54 | Extension.logToAIR("Registered successfully with token: " + registrationId); 55 | if (Extension.context == null) return; 56 | 57 | Extension.context.dispatchStatusEventAsync("TOKEN_SUCCESS", registrationId); 58 | } 59 | 60 | @Override 61 | protected void onRegistrationError(final Context context, final String string) { 62 | 63 | Extension.logToAIR("Error registering " + string); 64 | Extension.context.dispatchStatusEventAsync("TOKEN_FAIL", string); 65 | } 66 | 67 | @Override 68 | protected void onUnregistered(final Context context, final String registrationId) { 69 | 70 | Extension.logToAIR("Unregistered successfully"); 71 | Extension.context.dispatchStatusEventAsync("UNREGISTERED", registrationId); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/FPADMMessageReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * [SampleADMMessageReceiver.java] 3 | * 4 | * (c) 2019, Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | */ 6 | package com.freshplanet.ane.AirPushNotification; 7 | 8 | import com.amazon.device.messaging.ADMMessageReceiver; 9 | 10 | /** 11 | * The SampleADMMessageReceiver class listens for messages from ADM and forwards them. 12 | * 13 | * @version Revision: 1, Date: 11/20/2019 14 | */ 15 | public class FPADMMessageReceiver extends ADMMessageReceiver { 16 | public FPADMMessageReceiver() { 17 | super(FPADMMessageHandler.class); 18 | if(ADMHelper.IS_ADM_V2) { 19 | registerJobServiceClass(FPADMMessageHandlerJobBase.class, ADMHelper.JOB_ID); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/FetchStarterNotificationFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.util.Log; 18 | 19 | import com.adobe.fre.FREContext; 20 | import com.adobe.fre.FREFunction; 21 | import com.adobe.fre.FREObject; 22 | 23 | public class FetchStarterNotificationFunction implements FREFunction { 24 | 25 | private static String TAG = "NotifActivity"; 26 | 27 | 28 | @Override 29 | public FREObject call(FREContext arg0, FREObject[] arg1) { 30 | if(NotificationActivity.isComingFromNotification == null) { 31 | Log.e(TAG, "fetchStarterNotificationFunction called before NotificationActivity was created - not supposed to happen"); 32 | NotificationActivity.isComingFromNotification = false; 33 | } 34 | if (NotificationActivity.isComingFromNotification) 35 | { 36 | String params = NotificationActivity.notifParams; 37 | params = params == null ? "" : params; 38 | Log.d(TAG, "coming from notif :"+params); 39 | 40 | arg0.dispatchStatusEventAsync("APP_STARTING_FROM_NOTIFICATION", params); 41 | } else 42 | { 43 | Log.d(TAG, "not coming from notif"); 44 | } 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/GetCanSendUserToSettings.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Intent; 18 | import android.provider.Settings; 19 | import com.adobe.fre.FREContext; 20 | import com.adobe.fre.FREFunction; 21 | import com.adobe.fre.FREObject; 22 | import com.adobe.fre.FREWrongThreadException; 23 | 24 | /** 25 | * TODO placeholder code, don't use 26 | */ 27 | public class GetCanSendUserToSettings implements FREFunction 28 | { 29 | private Boolean checkedCanSend = false; 30 | private Boolean canSend = false; 31 | @Override 32 | public FREObject call(FREContext freContext, FREObject[] freObjects) { 33 | if(!checkedCanSend) { 34 | Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); 35 | canSend = intent.resolveActivity(freContext.getActivity().getPackageManager()) != null; 36 | checkedCanSend = true; 37 | } 38 | try { 39 | return FREObject.newObject(canSend); 40 | } catch (FREWrongThreadException e) { 41 | e.printStackTrace(); 42 | } 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/GetNotificationsEnabledFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | 19 | import androidx.core.app.NotificationManagerCompat; 20 | 21 | import com.adobe.fre.FREContext; 22 | import com.adobe.fre.FREFunction; 23 | import com.adobe.fre.FREObject; 24 | import com.adobe.fre.FREWrongThreadException; 25 | 26 | /** 27 | * TODO this may not do what I think it does, it's temp code 28 | */ 29 | public class GetNotificationsEnabledFunction implements FREFunction 30 | { 31 | private static final String TAG = "GetNotificationsEnabledFunction"; 32 | 33 | @Override 34 | public FREObject call(FREContext freContext, FREObject[] freObjects) { 35 | Context appContext = freContext.getActivity().getApplicationContext(); 36 | Extension.context.dispatchStatusEventAsync("GET_NOTIFICATIONS_ENABLED_RESULT", (NotificationManagerCompat.from(appContext).areNotificationsEnabled() ? "true" : "false")); 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/GoToNotifSettingsFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | import android.content.Intent; 19 | import android.net.Uri; 20 | import android.os.Build; 21 | import android.provider.Settings; 22 | 23 | import com.adobe.fre.FREContext; 24 | import com.adobe.fre.FREFunction; 25 | import com.adobe.fre.FREInvalidObjectException; 26 | import com.adobe.fre.FREObject; 27 | import com.adobe.fre.FRETypeMismatchException; 28 | import com.adobe.fre.FREWrongThreadException; 29 | 30 | public class GoToNotifSettingsFunction implements FREFunction 31 | { 32 | @Override 33 | public FREObject call(FREContext freContext, FREObject[] freObjects) { 34 | 35 | String channelId = null; 36 | if (freObjects.length > 0) { 37 | try { 38 | channelId = freObjects[0].getAsString(); 39 | if(channelId.equals("")) { 40 | channelId = null; 41 | } 42 | 43 | } catch (IllegalStateException e) { 44 | e.printStackTrace(); 45 | } catch (FRETypeMismatchException e) { 46 | e.printStackTrace(); 47 | } catch (FREInvalidObjectException e) { 48 | e.printStackTrace(); 49 | } catch (FREWrongThreadException e) { 50 | e.printStackTrace(); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | Context appContext = freContext.getActivity().getApplicationContext(); 57 | goToNotificationSettings(channelId, appContext); 58 | 59 | return null; 60 | } 61 | 62 | public void goToNotificationSettings(String channel, Context context) { 63 | Intent intent = new Intent(); 64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 65 | intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 66 | if (channel != null) { 67 | intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); 68 | intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel); 69 | } else { 70 | intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); 71 | } 72 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); 73 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 74 | if (channel != null) { 75 | intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); 76 | intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel); 77 | } else { 78 | intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); 79 | } 80 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); 81 | } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { 82 | intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); 83 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); 84 | } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ 85 | intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); 86 | intent.putExtra("app_package", context.getPackageName()); 87 | intent.putExtra("app_uid", context.getApplicationInfo().uid); 88 | } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { 89 | intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 90 | intent.addCategory(Intent.CATEGORY_DEFAULT); 91 | intent.setData(Uri.parse("package:" + context.getPackageName())); 92 | } 93 | context.startActivity(intent); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/LocalBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.BroadcastReceiver; 18 | import android.content.Context; 19 | import android.content.Intent; 20 | 21 | public class LocalBroadcastReceiver extends BroadcastReceiver 22 | { 23 | @Override 24 | public void onReceive(Context context, Intent intent) 25 | { 26 | try 27 | { 28 | String params = Extension.getParametersFromIntent(intent); 29 | 30 | Extension.logToAIR("Received local notification with parameters: " + params); 31 | 32 | // Build the notification if the app is not in foreground, otherwise just dispatch an event 33 | if (!Extension.isInForeground) 34 | { 35 | new CreateNotificationTask(context, intent).execute(); 36 | } 37 | else if (Extension.context != null) 38 | { 39 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_RECEIVED_WHEN_IN_FOREGROUND", params); 40 | } 41 | } 42 | catch (Exception e) 43 | { 44 | 45 | e.printStackTrace(); 46 | if (Extension.context != null) 47 | { 48 | Extension.context.dispatchStatusEventAsync("LOG_ISSUE", "LocalBroadcastReceiver: Unable to process local notification data : "+ e.getLocalizedMessage()); 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/LocalNotificationFunction.java: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2012 Freshplanet (http://freshplanet.com | opensource@freshplanet.com) 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | ////////////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | package com.freshplanet.ane.AirPushNotification; 21 | 22 | import java.util.Calendar; 23 | 24 | import android.app.AlarmManager; 25 | import android.app.PendingIntent; 26 | import android.content.Context; 27 | import android.content.Intent; 28 | import android.os.Build; 29 | import android.util.Log; 30 | import android.webkit.URLUtil; 31 | 32 | import com.adobe.fre.FREContext; 33 | import com.adobe.fre.FREFunction; 34 | import com.adobe.fre.FREInvalidObjectException; 35 | import com.adobe.fre.FREObject; 36 | import com.adobe.fre.FRETypeMismatchException; 37 | import com.adobe.fre.FREWrongThreadException; 38 | 39 | public class LocalNotificationFunction implements FREFunction { 40 | 41 | private static String TAG = "LocalNotificationFunction"; 42 | 43 | private static int RECURRENCE_NONE = 0; 44 | private static int RECURRENCE_DAY = 1; 45 | private static int RECURRENCE_WEEK = 2; 46 | private static int RECURRENCE_MONTH = 3; 47 | private static int RECURRENCE_YEAR = 4; 48 | 49 | private static int DEFAULT_NOTIFICATION_ID = 192837; 50 | 51 | /** 52 | * Doesn't do anything for now. just to ensure iOS compatibility. 53 | * 54 | */ 55 | public FREObject call(FREContext arg0, FREObject[] arg1) { 56 | 57 | String message = null; 58 | long timestamp = 0; 59 | String title = null; 60 | int recurrenceType = RECURRENCE_NONE; 61 | int notificationId = DEFAULT_NOTIFICATION_ID; 62 | String largeIconResourceId = null; 63 | String groupId = null; 64 | String categoryId = null; 65 | String deepLinkPath = null; 66 | boolean makeSquare = false; 67 | boolean isBannerNotification = false; 68 | 69 | try { 70 | message = arg1[0].getAsString(); 71 | timestamp = (long) arg1[1].getAsInt(); 72 | title = arg1[2].getAsString(); 73 | 74 | if (arg1.length >= 4) 75 | { 76 | recurrenceType = arg1[3].getAsInt(); 77 | } 78 | 79 | if (arg1.length >= 5) 80 | { 81 | notificationId = arg1[4].getAsInt(); 82 | } 83 | 84 | if (arg1.length >= 6) 85 | { 86 | deepLinkPath = arg1[5].getAsString(); 87 | } 88 | 89 | if (arg1.length >= 7 && arg1[6] != null) 90 | { 91 | largeIconResourceId = arg1[6].getAsString(); 92 | } 93 | 94 | if (arg1.length >= 8 && arg1[7] != null) 95 | { 96 | groupId = arg1[7].getAsString(); 97 | } 98 | 99 | if (arg1.length >= 9 && arg1[8] != null) 100 | { 101 | categoryId = arg1[8].getAsString(); 102 | } 103 | 104 | if (arg1.length >= 10 && arg1[9] != null) 105 | { 106 | makeSquare = arg1[9].getAsBool(); 107 | } 108 | 109 | if (arg1.length >= 11 && arg1[10] != null) 110 | { 111 | isBannerNotification = arg1[10].getAsBool(); 112 | } 113 | 114 | } catch (IllegalStateException e) { 115 | e.printStackTrace(); 116 | } catch (FRETypeMismatchException e) { 117 | e.printStackTrace(); 118 | } catch (FREInvalidObjectException e) { 119 | e.printStackTrace(); 120 | } catch (FREWrongThreadException e) { 121 | e.printStackTrace(); 122 | } catch (Exception e) { 123 | e.printStackTrace(); 124 | } 125 | 126 | if ((groupId == null || groupId.equals("")) && categoryId != null) { 127 | groupId = categoryId; 128 | } 129 | 130 | 131 | if (message != null && timestamp > 0) 132 | { 133 | Context appContext = arg0.getActivity().getApplicationContext(); 134 | timestamp *= 1000; // convert in ms 135 | Calendar cal = Calendar.getInstance(); 136 | if (cal.getTimeInMillis() > timestamp) 137 | { 138 | Log.d(TAG, "timestamp is older than current time"); 139 | return null; 140 | } 141 | 142 | Intent intent = new Intent(appContext, LocalBroadcastReceiver.class); 143 | intent.putExtra("isLocal", true); 144 | 145 | if (title != null) 146 | { 147 | intent.putExtra("contentTitle", title); 148 | } 149 | intent.putExtra("contentText", message); 150 | 151 | if (largeIconResourceId != null) 152 | { 153 | if(URLUtil.isHttpUrl(largeIconResourceId) || URLUtil.isHttpsUrl(largeIconResourceId)) { 154 | if(isBannerNotification) { 155 | intent.putExtra("bannerUrl", largeIconResourceId); 156 | } 157 | else { 158 | intent.putExtra("pictureUrl", largeIconResourceId); 159 | } 160 | } 161 | else { 162 | if(isBannerNotification) { 163 | intent.putExtra("largeBannerResourceId", largeIconResourceId); 164 | } 165 | else { 166 | intent.putExtra("largeIconResourceId", largeIconResourceId); 167 | } 168 | } 169 | } 170 | if (groupId != null) 171 | { 172 | intent.putExtra("groupId", groupId); 173 | } 174 | 175 | if (categoryId != null) 176 | { 177 | intent.putExtra("android_channel_id", categoryId); 178 | } 179 | 180 | if (deepLinkPath != null) 181 | { 182 | intent.putExtra("path", deepLinkPath); 183 | } 184 | 185 | intent.putExtra("notifId", notificationId); 186 | 187 | 188 | intent.putExtra("makeSquare", makeSquare); 189 | 190 | PendingIntent sender; 191 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { 192 | sender = PendingIntent.getBroadcast(appContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); 193 | } 194 | else { 195 | sender = PendingIntent.getBroadcast(appContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); 196 | } 197 | 198 | // Get the AlarmManager service 199 | AlarmManager am = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); 200 | 201 | am.cancel(sender); 202 | 203 | if (recurrenceType == RECURRENCE_DAY) 204 | { 205 | am.setRepeating(AlarmManager.RTC_WAKEUP, timestamp, 24*3600*1000, sender); 206 | } else if (recurrenceType == RECURRENCE_WEEK) { 207 | am.setRepeating(AlarmManager.RTC_WAKEUP, timestamp, 7*24*3600*1000, sender); 208 | } else if (recurrenceType == RECURRENCE_MONTH) { 209 | am.setRepeating(AlarmManager.RTC_WAKEUP, timestamp, 30*7*24*3600*1000, sender); 210 | 211 | } else if (recurrenceType == RECURRENCE_YEAR) { 212 | am.setRepeating(AlarmManager.RTC_WAKEUP, timestamp, 365*7*24*3600*1000, sender); 213 | 214 | } else 215 | { 216 | am.set(AlarmManager.RTC_WAKEUP, timestamp, sender); 217 | } 218 | Log.d(TAG, "setting params to run at "+Long.toString(timestamp)); 219 | 220 | } else 221 | { 222 | Log.d(TAG, "cannot set local notification, not enough params"); 223 | } 224 | 225 | 226 | return null; 227 | } 228 | 229 | } 230 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/NotificationActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.Activity; 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.util.Log; 21 | 22 | public class NotificationActivity extends Activity { 23 | 24 | private static String TAG = "NotifActivity"; 25 | 26 | public static String notifParams; 27 | public static Boolean isComingFromNotification; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | 32 | super.onCreate(savedInstanceState); 33 | Log.d(TAG, "create notif activity"); 34 | 35 | 36 | isComingFromNotification = false; 37 | 38 | Bundle values = this.getIntent().getExtras(); 39 | 40 | if (values != null && values.getString("params") != null) 41 | { 42 | Log.d(TAG, "notif has params: " + values.getString("params")); 43 | 44 | isComingFromNotification = true; 45 | notifParams = values.getString("params"); 46 | 47 | if (Extension.context != null) 48 | { 49 | Log.d(TAG, "context exists "+notifParams); 50 | Extension.context.dispatchStatusEventAsync("APP_BROUGHT_TO_FOREGROUND_FROM_NOTIFICATION", notifParams); 51 | isComingFromNotification = false; 52 | notifParams = null; 53 | } 54 | 55 | } 56 | 57 | boolean appStarted = tryStartApp("AIRAppEntry"); 58 | if (!appStarted) { 59 | Log.d(TAG, "Failed to start activity, falling back to legacy activity name"); 60 | tryStartApp("AppEntry"); 61 | } 62 | 63 | Log.d(TAG, "destroying activity"); 64 | finish(); 65 | } 66 | 67 | private boolean tryStartApp(String mainClass) { 68 | Intent intent; 69 | try { 70 | intent = new Intent(this, Class.forName(this.getPackageName() + "." + mainClass)); 71 | startActivity(intent); 72 | return true; 73 | } catch (ClassNotFoundException e) { 74 | e.printStackTrace(); 75 | return false; 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/NotificationPermissionActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.Manifest; 18 | import android.app.Activity; 19 | import android.content.Context; 20 | import android.content.pm.PackageManager; 21 | import android.util.Log; 22 | import android.os.Build; 23 | import android.os.Bundle; 24 | 25 | import androidx.annotation.NonNull; 26 | import androidx.core.app.ActivityCompat; 27 | import androidx.core.content.ContextCompat; 28 | 29 | public class NotificationPermissionActivity extends Activity { 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | 35 | if(savedInstanceState != null) { 36 | return; 37 | } 38 | 39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { 40 | if(ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { 41 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, 0); 42 | } 43 | else { 44 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_SETTINGS_ENABLED", ""); 45 | finish(); 46 | } 47 | } 48 | else { 49 | finish(); 50 | } 51 | } 52 | 53 | @Override 54 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 55 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 56 | int permissionCheck = PackageManager.PERMISSION_GRANTED; 57 | for (int permission : grantResults) { 58 | permissionCheck = permissionCheck + permission; 59 | } 60 | if ((grantResults.length > 0) && permissionCheck == PackageManager.PERMISSION_GRANTED) { 61 | // granted 62 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_SETTINGS_ENABLED", ""); 63 | } else { 64 | // denied - do nothing 65 | Extension.context.dispatchStatusEventAsync("NOTIFICATION_SETTINGS_DISABLED", ""); 66 | } 67 | finish(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/PingUrlTask.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.IOException; 19 | import java.io.InputStreamReader; 20 | import java.net.HttpURLConnection; 21 | import java.net.MalformedURLException; 22 | import java.net.URL; 23 | 24 | import android.os.AsyncTask; 25 | 26 | public class PingUrlTask extends AsyncTask { 27 | 28 | @Override 29 | protected Boolean doInBackground(String... urls) { 30 | 31 | String trackingUrl = urls[0]; 32 | 33 | Extension.logToAIR("start tracking "+trackingUrl); 34 | 35 | try { 36 | URL url = new URL(trackingUrl); 37 | 38 | HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); 39 | urlc.setRequestMethod("GET"); 40 | urlc.setRequestProperty("User-Agent", "Android"); 41 | urlc.setRequestProperty("Connection", "close"); 42 | urlc.setDoInput(true); 43 | urlc.setConnectTimeout(1000 * 10); 44 | urlc.connect(); 45 | 46 | // DO NOT REMOVE THIS CODE BLOCK, IF YOU DO TRACKING WONT WORK 47 | /////////////////////////////////////////////////////////////// 48 | switch (urlc.getResponseCode()) { 49 | case 200: 50 | case 201: 51 | BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); 52 | StringBuilder sb = new StringBuilder(); 53 | String line; 54 | while ((line = br.readLine()) != null) { 55 | sb.append(line+"\n"); 56 | } 57 | br.close(); 58 | 59 | Extension.logToAIR("Notification tracking response: " + sb.toString()); 60 | } 61 | 62 | } catch (MalformedURLException e1) { 63 | e1.printStackTrace(); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | /////////////////////////////////////////////////////////////// 68 | return null; 69 | } 70 | 71 | @Override 72 | protected void onPostExecute(Boolean downloadSuccess) 73 | { 74 | Extension.logToAIR("tracking complete"); 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/SetBadgeValueFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.content.Context; 18 | import android.util.Log; 19 | 20 | import com.adobe.fre.FREContext; 21 | import com.adobe.fre.FREFunction; 22 | import com.adobe.fre.FREObject; 23 | 24 | import me.leolin.shortcutbadger.ShortcutBadger; 25 | 26 | /** 27 | * Set the bage value around the app icon 28 | * @author titi, mateo-kozomara 29 | * 30 | */ 31 | public class SetBadgeValueFunction implements FREFunction { 32 | 33 | private static String TAG = "setBadgeNb"; 34 | 35 | public FREObject call(FREContext context, FREObject[] args) { 36 | 37 | if (args == null || args.length == 0) 38 | { 39 | Log.e(TAG, "No badge number provided. Cannot set badge number."); 40 | return null; 41 | } 42 | int badgeNumber = 0; 43 | try { 44 | badgeNumber = args[0].getAsInt(); 45 | } catch (Exception e) { 46 | Log.e(TAG, "Wrong object passed for badge number. Object expected : int. Cannot set badge number."); 47 | return null; 48 | } 49 | 50 | if (badgeNumber < 0) 51 | { 52 | badgeNumber = 0; 53 | } 54 | 55 | Context appContext = context.getActivity().getApplicationContext(); 56 | 57 | if(badgeNumber == 0) 58 | { 59 | ShortcutBadger.removeCount(appContext); 60 | } 61 | else 62 | { 63 | ShortcutBadger.applyCount(appContext, badgeNumber); 64 | } 65 | 66 | return null; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/SetIsAppInForegroundFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import com.adobe.fre.FREContext; 18 | import com.adobe.fre.FREFunction; 19 | import com.adobe.fre.FREInvalidObjectException; 20 | import com.adobe.fre.FREObject; 21 | import com.adobe.fre.FRETypeMismatchException; 22 | import com.adobe.fre.FREWrongThreadException; 23 | 24 | public class SetIsAppInForegroundFunction implements FREFunction { 25 | 26 | public FREObject call(FREContext arg0, FREObject[] arg1) { 27 | 28 | boolean isInForeground; 29 | try { 30 | isInForeground = arg1[0].getAsBool(); 31 | if(isInForeground) 32 | { 33 | MultiMsgNotification msg = MultiMsgNotification.Instance(arg0.getActivity()); 34 | msg.remove(); 35 | } 36 | } catch (IllegalStateException e) { 37 | e.printStackTrace(); 38 | return null; 39 | } catch (FRETypeMismatchException e) { 40 | e.printStackTrace(); 41 | return null; 42 | } catch (FREInvalidObjectException e) { 43 | e.printStackTrace(); 44 | return null; 45 | } catch (FREWrongThreadException e) { 46 | e.printStackTrace(); 47 | return null; 48 | } 49 | 50 | Extension.isInForeground = isInForeground; 51 | 52 | return null; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/SettingsLauncherActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.Activity; 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | 21 | /** 22 | * TODO this is all placeholder code. Don't use it 23 | */ 24 | public class SettingsLauncherActivity extends Activity 25 | { 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | } 30 | 31 | @Override 32 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 33 | super.onActivityResult(requestCode, resultCode, data); 34 | if(Extension.context != null) { 35 | //TODO see if there's any useful info I can pass here 36 | Extension.context.dispatchStatusEventAsync("COMPLETE", ""); 37 | } 38 | } 39 | 40 | @Override 41 | protected void onDestroy() { 42 | super.onDestroy(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /android/lib/src/main/java/com/freshplanet/ane/AirPushNotification/StoreNotifTrackingInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | package com.freshplanet.ane.AirPushNotification; 16 | 17 | import android.app.Activity; 18 | import android.content.Context; 19 | import android.content.SharedPreferences; 20 | 21 | import com.adobe.fre.FREContext; 22 | import com.adobe.fre.FREFunction; 23 | import com.adobe.fre.FREInvalidObjectException; 24 | import com.adobe.fre.FREObject; 25 | import com.adobe.fre.FRETypeMismatchException; 26 | import com.adobe.fre.FREWrongThreadException; 27 | 28 | public class StoreNotifTrackingInfo implements FREFunction { 29 | 30 | @Override 31 | public FREObject call(FREContext arg0, FREObject[] arg1) { 32 | 33 | Extension.logToAIR("start storing notif tracking"); 34 | 35 | if (arg1.length > 0) 36 | { 37 | String url = null; 38 | try { 39 | url = arg1[0].getAsString(); 40 | } catch (IllegalStateException e) { 41 | e.printStackTrace(); 42 | } catch (FRETypeMismatchException e) { 43 | e.printStackTrace(); 44 | } catch (FREInvalidObjectException e) { 45 | e.printStackTrace(); 46 | } catch (FREWrongThreadException e) { 47 | e.printStackTrace(); 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } 51 | 52 | if (url != null) { 53 | storeUrl(arg0.getActivity(), url); 54 | } else 55 | { 56 | Extension.logToAIR("url tracking is null"); 57 | } 58 | 59 | } else 60 | { 61 | Extension.logToAIR("no arguments providing to store tracking url"); 62 | } 63 | 64 | return null; 65 | } 66 | 67 | private void storeUrl(Activity act, String url) { 68 | 69 | // We need an Editor object to make preference changes. 70 | // All objects are from android.context.Context 71 | SharedPreferences settings = act.getSharedPreferences(Extension.PREFS_NAME, Context.MODE_PRIVATE); 72 | SharedPreferences.Editor editor = settings.edit(); 73 | editor.putString(Extension.PREFS_KEY, url); 74 | 75 | // Commit the edits! 76 | editor.apply(); 77 | 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/Badger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | 6 | import java.util.List; 7 | 8 | public interface Badger { 9 | 10 | /** 11 | * Called when user attempts to update notification count 12 | * @param context Caller context 13 | * @param componentName Component containing package and class name of calling application's 14 | * launcher activity 15 | * @param badgeCount Desired notification count 16 | * @throws ShortcutBadgeException 17 | */ 18 | void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException; 19 | 20 | /** 21 | * Called to let {@link ShortcutBadger} knows which launchers are supported by this badger. It should return a 22 | * @return List containing supported launchers package names 23 | */ 24 | List getSupportLaunchers(); 25 | } 26 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/ShortcutBadgeException.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger; 2 | 3 | public class ShortcutBadgeException extends Exception { 4 | public ShortcutBadgeException(String message) { 5 | super(message); 6 | } 7 | 8 | public ShortcutBadgeException(String message, Exception e) { 9 | super(message, e); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/ShortcutBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger; 2 | 3 | import android.app.Notification; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.pm.PackageManager; 8 | import android.content.pm.ResolveInfo; 9 | import android.os.Build; 10 | import android.util.Log; 11 | 12 | import java.lang.reflect.Field; 13 | import java.lang.reflect.Method; 14 | import java.util.LinkedList; 15 | import java.util.List; 16 | 17 | import me.leolin.shortcutbadger.impl.AdwHomeBadger; 18 | import me.leolin.shortcutbadger.impl.ApexHomeBadger; 19 | import me.leolin.shortcutbadger.impl.AsusHomeBadger; 20 | import me.leolin.shortcutbadger.impl.DefaultBadger; 21 | import me.leolin.shortcutbadger.impl.EverythingMeHomeBadger; 22 | import me.leolin.shortcutbadger.impl.HuaweiHomeBadger; 23 | import me.leolin.shortcutbadger.impl.NewHtcHomeBadger; 24 | import me.leolin.shortcutbadger.impl.NovaHomeBadger; 25 | import me.leolin.shortcutbadger.impl.OPPOHomeBader; 26 | import me.leolin.shortcutbadger.impl.SamsungHomeBadger; 27 | import me.leolin.shortcutbadger.impl.SonyHomeBadger; 28 | import me.leolin.shortcutbadger.impl.VivoHomeBadger; 29 | import me.leolin.shortcutbadger.impl.ZTEHomeBadger; 30 | import me.leolin.shortcutbadger.impl.ZukHomeBadger; 31 | 32 | 33 | /** 34 | * @author Leo Lin 35 | */ 36 | public final class ShortcutBadger { 37 | 38 | private static final String LOG_TAG = "ShortcutBadger"; 39 | private static final int SUPPORTED_CHECK_ATTEMPTS = 3; 40 | 41 | private static final List> BADGERS = new LinkedList>(); 42 | 43 | private volatile static Boolean sIsBadgeCounterSupported; 44 | private final static Object sCounterSupportedLock = new Object(); 45 | 46 | static { 47 | BADGERS.add(AdwHomeBadger.class); 48 | BADGERS.add(ApexHomeBadger.class); 49 | BADGERS.add(NewHtcHomeBadger.class); 50 | BADGERS.add(NovaHomeBadger.class); 51 | BADGERS.add(SonyHomeBadger.class); 52 | BADGERS.add(AsusHomeBadger.class); 53 | BADGERS.add(HuaweiHomeBadger.class); 54 | BADGERS.add(OPPOHomeBader.class); 55 | BADGERS.add(SamsungHomeBadger.class); 56 | BADGERS.add(ZukHomeBadger.class); 57 | BADGERS.add(VivoHomeBadger.class); 58 | BADGERS.add(ZTEHomeBadger.class); 59 | BADGERS.add(EverythingMeHomeBadger.class); 60 | } 61 | 62 | private static Badger sShortcutBadger; 63 | private static ComponentName sComponentName; 64 | 65 | /** 66 | * Tries to update the notification count 67 | * 68 | * @param context Caller context 69 | * @param badgeCount Desired badge count 70 | * @return true in case of success, false otherwise 71 | */ 72 | public static boolean applyCount(Context context, int badgeCount) { 73 | try { 74 | applyCountOrThrow(context, badgeCount); 75 | return true; 76 | } catch (ShortcutBadgeException e) { 77 | if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { 78 | Log.d(LOG_TAG, "Unable to execute badge", e); 79 | } 80 | return false; 81 | } 82 | } 83 | 84 | /** 85 | * Tries to update the notification count, throw a {@link ShortcutBadgeException} if it fails 86 | * 87 | * @param context Caller context 88 | * @param badgeCount Desired badge count 89 | */ 90 | public static void applyCountOrThrow(Context context, int badgeCount) throws ShortcutBadgeException { 91 | if (sShortcutBadger == null) { 92 | boolean launcherReady = initBadger(context); 93 | 94 | if (!launcherReady) 95 | throw new ShortcutBadgeException("No default launcher available"); 96 | } 97 | 98 | try { 99 | sShortcutBadger.executeBadge(context, sComponentName, badgeCount); 100 | } catch (Exception e) { 101 | throw new ShortcutBadgeException("Unable to execute badge", e); 102 | } 103 | } 104 | 105 | /** 106 | * Tries to remove the notification count 107 | * 108 | * @param context Caller context 109 | * @return true in case of success, false otherwise 110 | */ 111 | public static boolean removeCount(Context context) { 112 | return applyCount(context, 0); 113 | } 114 | 115 | /** 116 | * Tries to remove the notification count, throw a {@link ShortcutBadgeException} if it fails 117 | * 118 | * @param context Caller context 119 | */ 120 | public static void removeCountOrThrow(Context context) throws ShortcutBadgeException { 121 | applyCountOrThrow(context, 0); 122 | } 123 | 124 | /** 125 | * Whether this platform launcher supports shortcut badges. Doing this check causes the side 126 | * effect of resetting the counter if it's supported, so this method should be followed by 127 | * a call that actually sets the counter to the desired value, if the counter is supported. 128 | */ 129 | public static boolean isBadgeCounterSupported(Context context) { 130 | // Checking outside synchronized block to avoid synchronization in the common case (flag 131 | // already set), and improve perf. 132 | if (sIsBadgeCounterSupported == null) { 133 | synchronized (sCounterSupportedLock) { 134 | // Checking again inside synch block to avoid setting the flag twice. 135 | if (sIsBadgeCounterSupported == null) { 136 | String lastErrorMessage = null; 137 | for (int i = 0; i < SUPPORTED_CHECK_ATTEMPTS; i++) { 138 | try { 139 | Log.i(LOG_TAG, "Checking if platform supports badge counters, attempt " 140 | + String.format("%d/%d.", i + 1, SUPPORTED_CHECK_ATTEMPTS)); 141 | if (initBadger(context)) { 142 | sShortcutBadger.executeBadge(context, sComponentName, 0); 143 | sIsBadgeCounterSupported = true; 144 | Log.i(LOG_TAG, "Badge counter is supported in this platform."); 145 | break; 146 | } else { 147 | lastErrorMessage = "Failed to initialize the badge counter."; 148 | } 149 | } catch (Exception e) { 150 | // Keep retrying as long as we can. No need to dump the stack trace here 151 | // because this error will be the norm, not exception, for unsupported 152 | // platforms. So we just save the last error message to display later. 153 | lastErrorMessage = e.getMessage(); 154 | } 155 | } 156 | 157 | if (sIsBadgeCounterSupported == null) { 158 | Log.w(LOG_TAG, "Badge counter seems not supported for this platform: " 159 | + lastErrorMessage); 160 | sIsBadgeCounterSupported = false; 161 | } 162 | } 163 | } 164 | } 165 | return sIsBadgeCounterSupported; 166 | } 167 | 168 | /** 169 | * @param context Caller context 170 | * @param notification 171 | * @param badgeCount 172 | */ 173 | public static void applyNotification(Context context, Notification notification, int badgeCount) { 174 | if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) { 175 | try { 176 | Field field = notification.getClass().getDeclaredField("extraNotification"); 177 | Object extraNotification = field.get(notification); 178 | Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); 179 | method.invoke(extraNotification, badgeCount); 180 | } catch (Exception e) { 181 | if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { 182 | Log.d(LOG_TAG, "Unable to execute badge", e); 183 | } 184 | } 185 | } 186 | } 187 | 188 | // Initialize Badger if a launcher is availalble (eg. set as default on the device) 189 | // Returns true if a launcher is available, in this case, the Badger will be set and sShortcutBadger will be non null. 190 | private static boolean initBadger(Context context) { 191 | Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); 192 | if (launchIntent == null) { 193 | Log.e(LOG_TAG, "Unable to find launch intent for package " + context.getPackageName()); 194 | return false; 195 | } 196 | 197 | sComponentName = launchIntent.getComponent(); 198 | 199 | Intent intent = new Intent(Intent.ACTION_MAIN); 200 | intent.addCategory(Intent.CATEGORY_HOME); 201 | ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); 202 | 203 | if (resolveInfo == null || resolveInfo.activityInfo.name.toLowerCase().contains("resolver")) 204 | return false; 205 | 206 | String currentHomePackage = resolveInfo.activityInfo.packageName; 207 | 208 | for (Class badger : BADGERS) { 209 | Badger shortcutBadger = null; 210 | try { 211 | shortcutBadger = badger.newInstance(); 212 | } catch (Exception ignored) { 213 | } 214 | if (shortcutBadger != null && shortcutBadger.getSupportLaunchers().contains(currentHomePackage)) { 215 | sShortcutBadger = shortcutBadger; 216 | break; 217 | } 218 | } 219 | 220 | if (sShortcutBadger == null) { 221 | if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")) 222 | sShortcutBadger = new ZukHomeBadger(); 223 | else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")) 224 | sShortcutBadger = new OPPOHomeBader(); 225 | else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")) 226 | sShortcutBadger = new VivoHomeBadger(); 227 | else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")) 228 | sShortcutBadger = new ZTEHomeBadger(); 229 | else 230 | sShortcutBadger = new DefaultBadger(); 231 | } 232 | 233 | return true; 234 | } 235 | 236 | // Avoid anybody to instantiate this class 237 | private ShortcutBadger() { 238 | 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/AdwHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import me.leolin.shortcutbadger.Badger; 11 | import me.leolin.shortcutbadger.ShortcutBadgeException; 12 | import me.leolin.shortcutbadger.util.BroadcastHelper; 13 | 14 | /** 15 | * @author Gernot Pansy 16 | */ 17 | public class AdwHomeBadger implements Badger { 18 | 19 | public static final String INTENT_UPDATE_COUNTER = "org.adw.launcher.counter.SEND"; 20 | public static final String PACKAGENAME = "PNAME"; 21 | public static final String CLASSNAME = "CNAME"; 22 | public static final String COUNT = "COUNT"; 23 | 24 | @Override 25 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 26 | 27 | Intent intent = new Intent(INTENT_UPDATE_COUNTER); 28 | intent.putExtra(PACKAGENAME, componentName.getPackageName()); 29 | intent.putExtra(CLASSNAME, componentName.getClassName()); 30 | intent.putExtra(COUNT, badgeCount); 31 | if (BroadcastHelper.canResolveBroadcast(context, intent)) { 32 | context.sendBroadcast(intent); 33 | } else { 34 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 35 | } 36 | } 37 | 38 | @Override 39 | public List getSupportLaunchers() { 40 | return Arrays.asList( 41 | "org.adw.launcher", 42 | "org.adwfreak.launcher" 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/ApexHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import me.leolin.shortcutbadger.Badger; 11 | import me.leolin.shortcutbadger.ShortcutBadgeException; 12 | import me.leolin.shortcutbadger.util.BroadcastHelper; 13 | 14 | /** 15 | * @author Gernot Pansy 16 | */ 17 | public class ApexHomeBadger implements Badger { 18 | 19 | private static final String INTENT_UPDATE_COUNTER = "com.anddoes.launcher.COUNTER_CHANGED"; 20 | private static final String PACKAGENAME = "package"; 21 | private static final String COUNT = "count"; 22 | private static final String CLASS = "class"; 23 | 24 | @Override 25 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 26 | 27 | Intent intent = new Intent(INTENT_UPDATE_COUNTER); 28 | intent.putExtra(PACKAGENAME, componentName.getPackageName()); 29 | intent.putExtra(COUNT, badgeCount); 30 | intent.putExtra(CLASS, componentName.getClassName()); 31 | if (BroadcastHelper.canResolveBroadcast(context, intent)) { 32 | context.sendBroadcast(intent); 33 | } else { 34 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 35 | } 36 | } 37 | 38 | @Override 39 | public List getSupportLaunchers() { 40 | return Arrays.asList("com.anddoes.launcher"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/AsusHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import me.leolin.shortcutbadger.Badger; 11 | import me.leolin.shortcutbadger.ShortcutBadgeException; 12 | import me.leolin.shortcutbadger.util.BroadcastHelper; 13 | 14 | /** 15 | * @author leolin 16 | */ 17 | public class AsusHomeBadger implements Badger { 18 | 19 | private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; 20 | private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; 21 | private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; 22 | private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; 23 | 24 | @Override 25 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 26 | Intent intent = new Intent(INTENT_ACTION); 27 | intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount); 28 | intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName()); 29 | intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName()); 30 | intent.putExtra("badge_vip_count", 0); 31 | if (BroadcastHelper.canResolveBroadcast(context, intent)) { 32 | context.sendBroadcast(intent); 33 | } else { 34 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 35 | } 36 | } 37 | 38 | @Override 39 | public List getSupportLaunchers() { 40 | return Arrays.asList("com.asus.launcher"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/DefaultBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import me.leolin.shortcutbadger.Badger; 11 | import me.leolin.shortcutbadger.ShortcutBadgeException; 12 | import me.leolin.shortcutbadger.util.BroadcastHelper; 13 | 14 | /** 15 | * @author leolin 16 | */ 17 | public class DefaultBadger implements Badger { 18 | private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; 19 | private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; 20 | private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; 21 | private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; 22 | 23 | @Override 24 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 25 | Intent intent = new Intent(INTENT_ACTION); 26 | intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount); 27 | intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName()); 28 | intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName()); 29 | if (BroadcastHelper.canResolveBroadcast(context, intent)) { 30 | context.sendBroadcast(intent); 31 | } else { 32 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 33 | } 34 | } 35 | 36 | @Override 37 | public List getSupportLaunchers() { 38 | return new ArrayList(0); 39 | } 40 | 41 | boolean isSupported(Context context) { 42 | Intent intent = new Intent(INTENT_ACTION); 43 | return BroadcastHelper.canResolveBroadcast(context, intent); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/EverythingMeHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.ContentValues; 5 | import android.content.Context; 6 | import android.net.Uri; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | import me.leolin.shortcutbadger.Badger; 12 | import me.leolin.shortcutbadger.ShortcutBadgeException; 13 | 14 | 15 | /** 16 | * @author Radko Roman 17 | * @since 13.04.17. 18 | */ 19 | public class EverythingMeHomeBadger implements Badger { 20 | 21 | private static final String CONTENT_URI = "content://me.everything.badger/apps"; 22 | private static final String COLUMN_PACKAGE_NAME = "package_name"; 23 | private static final String COLUMN_ACTIVITY_NAME = "activity_name"; 24 | private static final String COLUMN_COUNT = "count"; 25 | 26 | @Override 27 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 28 | ContentValues contentValues = new ContentValues(); 29 | contentValues.put(COLUMN_PACKAGE_NAME, componentName.getPackageName()); 30 | contentValues.put(COLUMN_ACTIVITY_NAME, componentName.getClassName()); 31 | contentValues.put(COLUMN_COUNT, badgeCount); 32 | context.getContentResolver().insert(Uri.parse(CONTENT_URI), contentValues); 33 | } 34 | 35 | @Override 36 | public List getSupportLaunchers() { 37 | return Arrays.asList("me.everything.launcher"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/HuaweiHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | import me.leolin.shortcutbadger.Badger; 12 | import me.leolin.shortcutbadger.ShortcutBadgeException; 13 | 14 | /** 15 | * @author Jason Ling 16 | */ 17 | public class HuaweiHomeBadger implements Badger { 18 | 19 | @Override 20 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 21 | Bundle localBundle = new Bundle(); 22 | localBundle.putString("package", context.getPackageName()); 23 | localBundle.putString("class", componentName.getClassName()); 24 | localBundle.putInt("badgenumber", badgeCount); 25 | context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, localBundle); 26 | } 27 | 28 | @Override 29 | public List getSupportLaunchers() { 30 | return Arrays.asList( 31 | "com.huawei.android.launcher" 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/LGHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import me.leolin.shortcutbadger.Badger; 8 | import me.leolin.shortcutbadger.ShortcutBadgeException; 9 | import me.leolin.shortcutbadger.ShortcutBadger; 10 | import me.leolin.shortcutbadger.util.BroadcastHelper; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | /** 16 | * @author Leo Lin 17 | * Deprecated, LG devices will use DefaultBadger 18 | */ 19 | @Deprecated 20 | public class LGHomeBadger implements Badger { 21 | 22 | private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE"; 23 | private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count"; 24 | private static final String INTENT_EXTRA_PACKAGENAME = "badge_count_package_name"; 25 | private static final String INTENT_EXTRA_ACTIVITY_NAME = "badge_count_class_name"; 26 | 27 | @Override 28 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 29 | Intent intent = new Intent(INTENT_ACTION); 30 | intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount); 31 | intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName()); 32 | intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName()); 33 | if(BroadcastHelper.canResolveBroadcast(context, intent)) { 34 | context.sendBroadcast(intent); 35 | } else { 36 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 37 | } 38 | } 39 | 40 | @Override 41 | public List getSupportLaunchers() { 42 | return Arrays.asList( 43 | "com.lge.launcher", 44 | "com.lge.launcher2" 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/NewHtcHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import me.leolin.shortcutbadger.Badger; 8 | import me.leolin.shortcutbadger.ShortcutBadgeException; 9 | import me.leolin.shortcutbadger.ShortcutBadger; 10 | import me.leolin.shortcutbadger.util.BroadcastHelper; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | /** 16 | * @author Leo Lin 17 | */ 18 | public class NewHtcHomeBadger implements Badger { 19 | 20 | public static final String INTENT_UPDATE_SHORTCUT = "com.htc.launcher.action.UPDATE_SHORTCUT"; 21 | public static final String INTENT_SET_NOTIFICATION = "com.htc.launcher.action.SET_NOTIFICATION"; 22 | public static final String PACKAGENAME = "packagename"; 23 | public static final String COUNT = "count"; 24 | public static final String EXTRA_COMPONENT = "com.htc.launcher.extra.COMPONENT"; 25 | public static final String EXTRA_COUNT = "com.htc.launcher.extra.COUNT"; 26 | 27 | @Override 28 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 29 | 30 | Intent intent1 = new Intent(INTENT_SET_NOTIFICATION); 31 | intent1.putExtra(EXTRA_COMPONENT, componentName.flattenToShortString()); 32 | intent1.putExtra(EXTRA_COUNT, badgeCount); 33 | 34 | Intent intent = new Intent(INTENT_UPDATE_SHORTCUT); 35 | intent.putExtra(PACKAGENAME, componentName.getPackageName()); 36 | intent.putExtra(COUNT, badgeCount); 37 | 38 | if(BroadcastHelper.canResolveBroadcast(context, intent1) || BroadcastHelper.canResolveBroadcast(context, intent)) { 39 | context.sendBroadcast(intent1); 40 | context.sendBroadcast(intent); 41 | } else { 42 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 43 | } 44 | } 45 | 46 | @Override 47 | public List getSupportLaunchers() { 48 | return Arrays.asList("com.htc.launcher"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/NovaHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.ContentValues; 5 | import android.content.Context; 6 | import android.net.Uri; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | import me.leolin.shortcutbadger.Badger; 12 | import me.leolin.shortcutbadger.ShortcutBadgeException; 13 | 14 | /** 15 | * Shortcut Badger support for Nova Launcher. 16 | * TeslaUnread must be installed. 17 | * User: Gernot Pansy 18 | * Date: 2014/11/03 19 | * Time: 7:15 20 | */ 21 | public class NovaHomeBadger implements Badger { 22 | 23 | private static final String CONTENT_URI = "content://com.teslacoilsw.notifier/unread_count"; 24 | private static final String COUNT = "count"; 25 | private static final String TAG = "tag"; 26 | 27 | @Override 28 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 29 | ContentValues contentValues = new ContentValues(); 30 | contentValues.put(TAG, componentName.getPackageName() + "/" + componentName.getClassName()); 31 | contentValues.put(COUNT, badgeCount); 32 | context.getContentResolver().insert(Uri.parse(CONTENT_URI), contentValues); 33 | } 34 | 35 | @Override 36 | public List getSupportLaunchers() { 37 | return Arrays.asList("com.teslacoilsw.launcher"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/OPPOHomeBader.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | import java.lang.reflect.InvocationTargetException; 15 | import java.lang.reflect.Method; 16 | import java.util.Collections; 17 | import java.util.List; 18 | 19 | import me.leolin.shortcutbadger.Badger; 20 | import me.leolin.shortcutbadger.ShortcutBadgeException; 21 | import me.leolin.shortcutbadger.util.BroadcastHelper; 22 | import me.leolin.shortcutbadger.util.CloseHelper; 23 | 24 | /** 25 | * Created by NingSo on 2016/10/14.上午10:09 26 | * 27 | * @author: NingSo 28 | * Email: ningso.ping@gmail.com 29 | *

30 | * OPPO R9 not supported 31 | * Version number 6 applies only to chat-type apps 32 | */ 33 | 34 | public class OPPOHomeBader implements Badger { 35 | 36 | private static final String PROVIDER_CONTENT_URI = "content://com.android.badge/badge"; 37 | private static final String INTENT_ACTION = "com.oppo.unsettledevent"; 38 | private static final String INTENT_EXTRA_PACKAGENAME = "pakeageName"; 39 | private static final String INTENT_EXTRA_BADGE_COUNT = "number"; 40 | private static final String INTENT_EXTRA_BADGE_UPGRADENUMBER = "upgradeNumber"; 41 | private static final String INTENT_EXTRA_BADGEUPGRADE_COUNT = "app_badge_count"; 42 | private static int ROMVERSION = -1; 43 | 44 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 45 | @Override 46 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 47 | if (badgeCount == 0) { 48 | badgeCount = -1; 49 | } 50 | Intent intent = new Intent(INTENT_ACTION); 51 | intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName()); 52 | intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount); 53 | intent.putExtra(INTENT_EXTRA_BADGE_UPGRADENUMBER, badgeCount); 54 | if (BroadcastHelper.canResolveBroadcast(context, intent)) { 55 | context.sendBroadcast(intent); 56 | } else { 57 | int version = getSupportVersion(); 58 | if (version == 6) { 59 | try { 60 | Bundle extras = new Bundle(); 61 | extras.putInt(INTENT_EXTRA_BADGEUPGRADE_COUNT, badgeCount); 62 | context.getContentResolver().call(Uri.parse(PROVIDER_CONTENT_URI), "setAppBadgeCount", null, extras); 63 | } catch (Throwable th) { 64 | throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); 65 | } 66 | } 67 | } 68 | } 69 | 70 | @Override 71 | public List getSupportLaunchers() { 72 | return Collections.singletonList("com.oppo.launcher"); 73 | } 74 | 75 | private int getSupportVersion() { 76 | int i = ROMVERSION; 77 | if (i >= 0) { 78 | return ROMVERSION; 79 | } 80 | try { 81 | i = ((Integer) executeClassLoad(getClass("com.color.os.ColorBuild"), "getColorOSVERSION", null, null)).intValue(); 82 | } catch (Exception e) { 83 | i = 0; 84 | } 85 | if (i == 0) { 86 | try { 87 | String str = getSystemProperty("ro.build.version.opporom"); 88 | if (str.startsWith("V1.4")) { 89 | return 3; 90 | } 91 | if (str.startsWith("V2.0")) { 92 | return 4; 93 | } 94 | if (str.startsWith("V2.1")) { 95 | return 5; 96 | } 97 | } catch (Exception ignored) { 98 | 99 | } 100 | } 101 | ROMVERSION = i; 102 | return ROMVERSION; 103 | } 104 | 105 | 106 | private Object executeClassLoad(Class cls, String str, Class[] clsArr, Object[] objArr) { 107 | Object obj = null; 108 | if (!(cls == null || checkObjExists(str))) { 109 | Method method = getMethod(cls, str, clsArr); 110 | if (method != null) { 111 | method.setAccessible(true); 112 | try { 113 | obj = method.invoke(null, objArr); 114 | } catch (IllegalAccessException e) { 115 | e.printStackTrace(); 116 | } catch (InvocationTargetException e) { 117 | e.printStackTrace(); 118 | } 119 | } 120 | } 121 | return obj; 122 | } 123 | 124 | private Method getMethod(Class cls, String str, Class[] clsArr) { 125 | Method method = null; 126 | if (cls == null || checkObjExists(str)) { 127 | return method; 128 | } 129 | try { 130 | cls.getMethods(); 131 | cls.getDeclaredMethods(); 132 | return cls.getDeclaredMethod(str, clsArr); 133 | } catch (Exception e) { 134 | try { 135 | return cls.getMethod(str, clsArr); 136 | } catch (Exception e2) { 137 | return cls.getSuperclass() != null ? getMethod(cls.getSuperclass(), str, clsArr) : method; 138 | } 139 | } 140 | } 141 | 142 | private Class getClass(String str) { 143 | Class cls = null; 144 | try { 145 | cls = Class.forName(str); 146 | } catch (ClassNotFoundException ignored) { 147 | } 148 | return cls; 149 | } 150 | 151 | 152 | private boolean checkObjExists(Object obj) { 153 | return obj == null || obj.toString().equals("") || obj.toString().trim().equals("null"); 154 | } 155 | 156 | 157 | private String getSystemProperty(String propName) { 158 | String line; 159 | BufferedReader input = null; 160 | try { 161 | Process p = Runtime.getRuntime().exec("getprop " + propName); 162 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); 163 | line = input.readLine(); 164 | input.close(); 165 | } catch (IOException ex) { 166 | return null; 167 | } finally { 168 | CloseHelper.closeQuietly(input); 169 | } 170 | return line; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/SamsungHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.ContentResolver; 5 | import android.content.ContentValues; 6 | import android.content.Context; 7 | import android.database.Cursor; 8 | import android.net.Uri; 9 | import android.os.Build; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import me.leolin.shortcutbadger.Badger; 15 | import me.leolin.shortcutbadger.ShortcutBadgeException; 16 | import me.leolin.shortcutbadger.util.CloseHelper; 17 | 18 | /** 19 | * @author Leo Lin 20 | */ 21 | public class SamsungHomeBadger implements Badger { 22 | private static final String CONTENT_URI = "content://com.sec.badge/apps?notify=true"; 23 | private static final String[] CONTENT_PROJECTION = new String[]{"_id", "class"}; 24 | 25 | private DefaultBadger defaultBadger; 26 | 27 | public SamsungHomeBadger() { 28 | if (Build.VERSION.SDK_INT >= 21) { 29 | defaultBadger = new DefaultBadger(); 30 | } 31 | } 32 | 33 | @Override 34 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 35 | if (defaultBadger != null && defaultBadger.isSupported(context)) { 36 | defaultBadger.executeBadge(context, componentName, badgeCount); 37 | } else { 38 | Uri mUri = Uri.parse(CONTENT_URI); 39 | ContentResolver contentResolver = context.getContentResolver(); 40 | Cursor cursor = null; 41 | try { 42 | cursor = contentResolver.query(mUri, CONTENT_PROJECTION, "package=?", new String[]{componentName.getPackageName()}, null); 43 | if (cursor != null) { 44 | String entryActivityName = componentName.getClassName(); 45 | boolean entryActivityExist = false; 46 | while (cursor.moveToNext()) { 47 | int id = cursor.getInt(0); 48 | ContentValues contentValues = getContentValues(componentName, badgeCount, false); 49 | contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)}); 50 | if (entryActivityName.equals(cursor.getString(cursor.getColumnIndex("class")))) { 51 | entryActivityExist = true; 52 | } 53 | } 54 | 55 | if (!entryActivityExist) { 56 | ContentValues contentValues = getContentValues(componentName, badgeCount, true); 57 | contentResolver.insert(mUri, contentValues); 58 | } 59 | } 60 | } finally { 61 | CloseHelper.close(cursor); 62 | } 63 | } 64 | } 65 | 66 | private ContentValues getContentValues(ComponentName componentName, int badgeCount, boolean isInsert) { 67 | ContentValues contentValues = new ContentValues(); 68 | if (isInsert) { 69 | contentValues.put("package", componentName.getPackageName()); 70 | contentValues.put("class", componentName.getClassName()); 71 | } 72 | 73 | contentValues.put("badgecount", badgeCount); 74 | 75 | return contentValues; 76 | } 77 | 78 | @Override 79 | public List getSupportLaunchers() { 80 | return Arrays.asList( 81 | "com.sec.android.app.launcher", 82 | "com.sec.android.app.twlauncher" 83 | ); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/SonyHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.AsyncQueryHandler; 4 | import android.content.ComponentName; 5 | import android.content.ContentValues; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.pm.ProviderInfo; 9 | import android.net.Uri; 10 | import android.os.Looper; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | import me.leolin.shortcutbadger.Badger; 16 | import me.leolin.shortcutbadger.ShortcutBadgeException; 17 | 18 | 19 | /** 20 | * @author Leo Lin 21 | */ 22 | public class SonyHomeBadger implements Badger { 23 | 24 | private static final String INTENT_ACTION = "com.sonyericsson.home.action.UPDATE_BADGE"; 25 | private static final String INTENT_EXTRA_PACKAGE_NAME = "com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME"; 26 | private static final String INTENT_EXTRA_ACTIVITY_NAME = "com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME"; 27 | private static final String INTENT_EXTRA_MESSAGE = "com.sonyericsson.home.intent.extra.badge.MESSAGE"; 28 | private static final String INTENT_EXTRA_SHOW_MESSAGE = "com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE"; 29 | 30 | private static final String PROVIDER_CONTENT_URI = "content://com.sonymobile.home.resourceprovider/badge"; 31 | private static final String PROVIDER_COLUMNS_BADGE_COUNT = "badge_count"; 32 | private static final String PROVIDER_COLUMNS_PACKAGE_NAME = "package_name"; 33 | private static final String PROVIDER_COLUMNS_ACTIVITY_NAME = "activity_name"; 34 | private static final String SONY_HOME_PROVIDER_NAME = "com.sonymobile.home.resourceprovider"; 35 | private final Uri BADGE_CONTENT_URI = Uri.parse(PROVIDER_CONTENT_URI); 36 | 37 | private AsyncQueryHandler mQueryHandler; 38 | 39 | @Override 40 | public void executeBadge(Context context, ComponentName componentName, 41 | int badgeCount) throws ShortcutBadgeException { 42 | if (sonyBadgeContentProviderExists(context)) { 43 | executeBadgeByContentProvider(context, componentName, badgeCount); 44 | } else { 45 | executeBadgeByBroadcast(context, componentName, badgeCount); 46 | } 47 | } 48 | 49 | @Override 50 | public List getSupportLaunchers() { 51 | return Arrays.asList("com.sonyericsson.home", "com.sonymobile.home"); 52 | } 53 | 54 | private static void executeBadgeByBroadcast(Context context, ComponentName componentName, 55 | int badgeCount) { 56 | Intent intent = new Intent(INTENT_ACTION); 57 | intent.putExtra(INTENT_EXTRA_PACKAGE_NAME, componentName.getPackageName()); 58 | intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName()); 59 | intent.putExtra(INTENT_EXTRA_MESSAGE, String.valueOf(badgeCount)); 60 | intent.putExtra(INTENT_EXTRA_SHOW_MESSAGE, badgeCount > 0); 61 | context.sendBroadcast(intent); 62 | } 63 | 64 | /** 65 | * Send request to Sony badge content provider to set badge in Sony home launcher. 66 | * 67 | * @param context the context to use 68 | * @param componentName the componentName to use 69 | * @param badgeCount the badge count 70 | */ 71 | private void executeBadgeByContentProvider(Context context, ComponentName componentName, 72 | int badgeCount) { 73 | if (badgeCount < 0) { 74 | return; 75 | } 76 | 77 | final ContentValues contentValues = createContentValues(badgeCount, componentName); 78 | if (Looper.myLooper() == Looper.getMainLooper()) { 79 | // We're in the main thread. Let's ensure the badge update happens in a background 80 | // thread by using an AsyncQueryHandler and an async update. 81 | if (mQueryHandler == null) { 82 | mQueryHandler = new AsyncQueryHandler( 83 | context.getApplicationContext().getContentResolver()) { 84 | }; 85 | } 86 | insertBadgeAsync(contentValues); 87 | } else { 88 | // Already in a background thread. Let's update the badge synchronously. Otherwise, 89 | // if we use the AsyncQueryHandler, this thread may already be dead by the time the 90 | // async execution finishes, which will lead to an IllegalStateException. 91 | insertBadgeSync(context, contentValues); 92 | } 93 | } 94 | 95 | /** 96 | * Asynchronously inserts the badge counter. 97 | * 98 | * @param contentValues Content values containing the badge count, package and activity names 99 | */ 100 | private void insertBadgeAsync(final ContentValues contentValues) { 101 | mQueryHandler.startInsert(0, null, BADGE_CONTENT_URI, contentValues); 102 | } 103 | 104 | /** 105 | * Synchronously inserts the badge counter. 106 | * 107 | * @param context Caller context 108 | * @param contentValues Content values containing the badge count, package and activity names 109 | */ 110 | private void insertBadgeSync(final Context context, final ContentValues contentValues) { 111 | context.getApplicationContext().getContentResolver() 112 | .insert(BADGE_CONTENT_URI, contentValues); 113 | } 114 | 115 | /** 116 | * Creates a ContentValues object to be used in the badge counter update. The package and 117 | * activity names must correspond to an activity that holds an intent filter with action 118 | * "android.intent.action.MAIN" and category android.intent.category.LAUNCHER" in the manifest. 119 | * Also, it is not allowed to publish badges on behalf of another client, so the package and 120 | * activity names must belong to the process from which the insert is made. 121 | * To be able to insert badges, the app must have the PROVIDER_INSERT_BADGE 122 | * permission in the manifest file. In case these conditions are not 123 | * fulfilled, or any content values are missing, there will be an unhandled 124 | * exception on the background thread. 125 | * 126 | * @param badgeCount the badge count 127 | * @param componentName the component name from which package and class name will be extracted 128 | * 129 | */ 130 | private ContentValues createContentValues(final int badgeCount, 131 | final ComponentName componentName) { 132 | final ContentValues contentValues = new ContentValues(); 133 | contentValues.put(PROVIDER_COLUMNS_BADGE_COUNT, badgeCount); 134 | contentValues.put(PROVIDER_COLUMNS_PACKAGE_NAME, componentName.getPackageName()); 135 | contentValues.put(PROVIDER_COLUMNS_ACTIVITY_NAME, componentName.getClassName()); 136 | return contentValues; 137 | } 138 | 139 | /** 140 | * Check if the latest Sony badge content provider exists . 141 | * 142 | * @param context the context to use 143 | * @return true if Sony badge content provider exists, otherwise false. 144 | */ 145 | private static boolean sonyBadgeContentProviderExists(Context context) { 146 | boolean exists = false; 147 | ProviderInfo info = context.getPackageManager().resolveContentProvider(SONY_HOME_PROVIDER_NAME, 0); 148 | if (info != null) { 149 | exists = true; 150 | } 151 | return exists; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/VivoHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import me.leolin.shortcutbadger.Badger; 11 | import me.leolin.shortcutbadger.ShortcutBadgeException; 12 | 13 | /** 14 | * @author leolin 15 | */ 16 | public class VivoHomeBadger implements Badger { 17 | 18 | @Override 19 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 20 | Intent intent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM"); 21 | intent.putExtra("packageName", context.getPackageName()); 22 | intent.putExtra("className", componentName.getClassName()); 23 | intent.putExtra("notificationNum", badgeCount); 24 | context.sendBroadcast(intent); 25 | } 26 | 27 | @Override 28 | public List getSupportLaunchers() { 29 | return Arrays.asList("com.vivo.launcher"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/XiaomiHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Notification; 5 | import android.app.NotificationManager; 6 | import android.content.ComponentName; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.pm.PackageManager; 10 | import android.content.pm.ResolveInfo; 11 | import android.os.Build; 12 | 13 | import java.lang.reflect.Field; 14 | import java.lang.reflect.Method; 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | import me.leolin.shortcutbadger.Badger; 19 | import me.leolin.shortcutbadger.ShortcutBadgeException; 20 | import me.leolin.shortcutbadger.util.BroadcastHelper; 21 | 22 | 23 | /** 24 | * @author leolin 25 | */ 26 | @Deprecated 27 | public class XiaomiHomeBadger implements Badger { 28 | 29 | public static final String INTENT_ACTION = "android.intent.action.APPLICATION_MESSAGE_UPDATE"; 30 | public static final String EXTRA_UPDATE_APP_COMPONENT_NAME = "android.intent.extra.update_application_component_name"; 31 | public static final String EXTRA_UPDATE_APP_MSG_TEXT = "android.intent.extra.update_application_message_text"; 32 | private ResolveInfo resolveInfo; 33 | 34 | @Override 35 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 36 | try { 37 | Class miuiNotificationClass = Class.forName("android.app.MiuiNotification"); 38 | Object miuiNotification = miuiNotificationClass.newInstance(); 39 | Field field = miuiNotification.getClass().getDeclaredField("messageCount"); 40 | field.setAccessible(true); 41 | try { 42 | field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount)); 43 | } catch (Exception e) { 44 | field.set(miuiNotification, badgeCount); 45 | } 46 | } catch (Exception e) { 47 | Intent localIntent = new Intent( 48 | INTENT_ACTION); 49 | localIntent.putExtra(EXTRA_UPDATE_APP_COMPONENT_NAME, componentName.getPackageName() + "/" + componentName.getClassName()); 50 | localIntent.putExtra(EXTRA_UPDATE_APP_MSG_TEXT, String.valueOf(badgeCount == 0 ? "" : badgeCount)); 51 | if (BroadcastHelper.canResolveBroadcast(context, localIntent)) { 52 | context.sendBroadcast(localIntent); 53 | } 54 | } 55 | if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) { 56 | tryNewMiuiBadge(context, badgeCount); 57 | } 58 | } 59 | 60 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 61 | private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { 62 | if (resolveInfo == null) { 63 | Intent intent = new Intent(Intent.ACTION_MAIN); 64 | intent.addCategory(Intent.CATEGORY_HOME); 65 | resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); 66 | } 67 | 68 | if (resolveInfo != null) { 69 | NotificationManager mNotificationManager = (NotificationManager) context 70 | .getSystemService(Context.NOTIFICATION_SERVICE); 71 | Notification.Builder builder = new Notification.Builder(context) 72 | .setContentTitle("") 73 | .setContentText("") 74 | .setSmallIcon(resolveInfo.getIconResource()); 75 | Notification notification = builder.build(); 76 | try { 77 | Field field = notification.getClass().getDeclaredField("extraNotification"); 78 | Object extraNotification = field.get(notification); 79 | Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); 80 | method.invoke(extraNotification, badgeCount); 81 | mNotificationManager.notify(0, notification); 82 | } catch (Exception e) { 83 | throw new ShortcutBadgeException("not able to set badge", e); 84 | } 85 | } 86 | } 87 | 88 | @Override 89 | public List getSupportLaunchers() { 90 | return Arrays.asList( 91 | "com.miui.miuilite", 92 | "com.miui.home", 93 | "com.miui.miuihome", 94 | "com.miui.miuihome2", 95 | "com.miui.mihome", 96 | "com.miui.mihome2", 97 | "com.i.miui.launcher" 98 | ); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/ZTEHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import me.leolin.shortcutbadger.Badger; 13 | import me.leolin.shortcutbadger.ShortcutBadgeException; 14 | 15 | public class ZTEHomeBadger implements Badger { 16 | 17 | @Override 18 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) 19 | throws ShortcutBadgeException { 20 | Bundle extra = new Bundle(); 21 | extra.putInt("app_badge_count", badgeCount); 22 | extra.putString("app_badge_component_name", componentName.flattenToString()); 23 | 24 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 25 | context.getContentResolver().call( 26 | Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"), 27 | "setAppUnreadCount", null, extra); 28 | } 29 | } 30 | 31 | @Override 32 | public List getSupportLaunchers() { 33 | return new ArrayList(0); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/impl/ZukHomeBadger.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.impl; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.net.Uri; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | import me.leolin.shortcutbadger.Badger; 14 | import me.leolin.shortcutbadger.ShortcutBadgeException; 15 | 16 | /** 17 | * Created by wuxuejian on 2016/10/9. 18 | * 需在设置 -- 通知和状态栏 -- 应用角标管理 中开启应用 19 | */ 20 | 21 | public class ZukHomeBadger implements Badger { 22 | 23 | private final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge"); 24 | 25 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 26 | @Override 27 | public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { 28 | Bundle extra = new Bundle(); 29 | extra.putInt("app_badge_count", badgeCount); 30 | context.getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra); 31 | } 32 | 33 | @Override 34 | public List getSupportLaunchers() { 35 | return Collections.singletonList("com.zui.launcher"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/util/BroadcastHelper.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.util; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.content.pm.ResolveInfo; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by mahijazi on 17/05/16. 12 | */ 13 | public class BroadcastHelper { 14 | public static boolean canResolveBroadcast(Context context, Intent intent) { 15 | PackageManager packageManager = context.getPackageManager(); 16 | List receivers = packageManager.queryBroadcastReceivers(intent, 0); 17 | return receivers != null && receivers.size() > 0; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /android/lib/src/main/java/me/leolin/shortcutbadger/util/CloseHelper.java: -------------------------------------------------------------------------------- 1 | package me.leolin.shortcutbadger.util; 2 | 3 | import android.database.Cursor; 4 | 5 | import java.io.Closeable; 6 | import java.io.IOException; 7 | 8 | /** 9 | * @author leolin 10 | */ 11 | public class CloseHelper { 12 | 13 | public static void close(Cursor cursor) { 14 | if (cursor != null && !cursor.isClosed()) { 15 | cursor.close(); 16 | } 17 | } 18 | 19 | 20 | public static void closeQuietly(Closeable closeable) { 21 | try { 22 | if (closeable != null) { 23 | closeable.close(); 24 | } 25 | } catch (IOException var2) { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /android/lib/src/main/res/drawable-xhdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/src/main/res/drawable-xhdpi/app_icon.png -------------------------------------------------------------------------------- /android/lib/src/main/res/drawable-xhdpi/icon72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/src/main/res/drawable-xhdpi/icon72.png -------------------------------------------------------------------------------- /android/lib/src/main/res/drawable-xhdpi/status_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/src/main/res/drawable-xhdpi/status_icon.png -------------------------------------------------------------------------------- /android/lib/src/main/res/drawable-xhdpi/status_icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/android/lib/src/main/res/drawable-xhdpi/status_icon24.png -------------------------------------------------------------------------------- /android/lib/src/main/res/layout/bannernotificationcontentview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /android/lib/src/main/res/layout/bigcontentview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 20 | 21 | 22 | 31 | 32 | 41 | 42 | 43 | 52 | 53 | 61 | 62 | -------------------------------------------------------------------------------- /android/lib/src/main/res/layout/contentview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 23 | 24 | 35 | 36 | 45 | 46 | 54 | 55 | -------------------------------------------------------------------------------- /android/lib/src/main/res/layout/inflatelayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | 27 | -------------------------------------------------------------------------------- /android/lib/src/main/res/values/push_colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF2DA9F9 4 | -------------------------------------------------------------------------------- /android/lib/src/main/res/values/push_styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 12 | 13 | 19 | 20 | 24 | 25 | 29 | 33 | 34 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':lib' -------------------------------------------------------------------------------- /bin/AirPushNotification.ane: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/bin/AirPushNotification.ane -------------------------------------------------------------------------------- /bin/AirPushNotification_multiMsg.ane: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/bin/AirPushNotification_multiMsg.ane -------------------------------------------------------------------------------- /build/ant-contrib-0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freshplanet/ANE-Push-Notification/b8488a96e084ea558f26a24469d6f64dc9b2113b/build/ant-contrib-0.6.jar -------------------------------------------------------------------------------- /build/example.build.config: -------------------------------------------------------------------------------- 1 | name = AirPushNotification 2 | useMultiMsg = false 3 | air.sdk.home = /path/to/your/air/sdk 4 | android.sdk.home = /path/to/your/android/sdk 5 | ios.res = /path/to/your/notification/assets 6 | include.res = true -------------------------------------------------------------------------------- /build/extension.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | com.freshplanet.ane.AirPushNotification 21 | 2.0.0 22 | 23 | 24 | 25 | 26 | libAirPushNotification.a 27 | AirPushNotificationInitializer 28 | AirPushNotificationFinalizer 29 | 30 | 31 | 32 | 33 | 34 | AirPushNotificationMac.framework 35 | AirPushNotificationInitializer 36 | AirPushNotificationFinalizer 37 | 38 | 39 | 40 | 41 | 42 | libAirPushNotification.jar 43 | com.freshplanet.ane.AirPushNotification.Extension 44 | com.freshplanet.ane.AirPushNotification.Extension 45 | 46 | 47 | 48 | 49 | 50 | libAirPushNotification.jar 51 | com.freshplanet.ane.AirPushNotification.Extension 52 | com.freshplanet.ane.AirPushNotification.Extension 53 | 54 | 55 | 56 | 57 | 58 | libAirPushNotification.jar 59 | com.freshplanet.ane.AirPushNotification.Extension 60 | com.freshplanet.ane.AirPushNotification.Extension 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /build/platform-android.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | firebase-messaging-23.1.2.jar 43 | play-services-cloud-messaging-17.0.1.jar 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | com.freshplanet.ane.AirPushNotification 72 | airpushnotif-res 73 | 74 | 75 | -------------------------------------------------------------------------------- /build/platform-ios.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 11.0 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ios/AirPushNotification.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/AirPushNotification.xcodeproj/xcshareddata/xcschemes/AirPushNotificationMac.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /ios/AirPushNotification.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/AirPushNotification/AirPushNotification.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | #include 16 | #import 17 | #if TARGET_OS_IPHONE 18 | #import 19 | #elif TARGET_OS_OSX 20 | #import 21 | #import 22 | #endif 23 | #import "FlashRuntimeExtensions.h" 24 | 25 | 26 | 27 | static NSString* const storedNotifTrackingUrl = @"storedNotifTrackingUrl"; 28 | 29 | #if TARGET_OS_IPHONE 30 | @interface AirPushNotification : NSObject { 31 | FREContext _context; 32 | } 33 | #elif TARGET_OS_OSX 34 | @interface AirPushNotification : NSObject { 35 | FREContext _context; 36 | } 37 | #endif 38 | 39 | + (AirPushNotification*)instance; 40 | + (NSString*)convertToJSonString:(NSDictionary*)dict; 41 | 42 | - (BOOL) isInitialized; 43 | #if TARGET_OS_IPHONE 44 | - (void)trackRemoteNofiticationFromApp:(UIApplication*)app andUserInfo:(NSDictionary*)userInfo; 45 | #elif TARGET_OS_OSX 46 | - (void)trackRemoteNofiticationFromApp:(NSApplication*)app andUserInfo:(NSDictionary*)userInfo; 47 | #endif 48 | - (void)sendEvent:(NSString*)code; 49 | - (void)sendLog:(NSString*)log; 50 | - (void)sendEvent:(NSString*)code level:(NSString*)level; 51 | 52 | 53 | @end 54 | 55 | void AirPushNotificationContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet); 56 | void AirPushNotificationContextFinalizer(FREContext ctx); 57 | void AirPushNotificationInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet); 58 | void AirPushNotificationFinalizer(void *extData); 59 | 60 | -------------------------------------------------------------------------------- /ios/AirPushNotification/NotifCenterDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include 17 | #if TARGET_OS_IPHONE 18 | #import 19 | #elif TARGET_OS_OSX 20 | #import 21 | #import 22 | #endif 23 | #import 24 | 25 | @interface NotifCenterDelegate : NSObject 26 | @property(nonatomic, strong) NSDictionary* starterNotif; 27 | @property(nonatomic, assign) BOOL pendingOpenAppNotificationSettings; 28 | 29 | - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response 30 | withCompletionHandler:(void (^)(void))completionHandler; 31 | 32 | - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler; 33 | 34 | -(void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification; 35 | 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /ios/AirPushNotification/NotifCenterDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 FreshPlanet 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #import "NotifCenterDelegate.h" 17 | #import "AirPushNotification.h" 18 | 19 | @interface NotifCenterDelegate() 20 | @end 21 | 22 | @implementation NotifCenterDelegate 23 | 24 | - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response 25 | withCompletionHandler:(void (^)(void))completionHandler { 26 | NSDictionary * notifDict = response.notification.request.content.userInfo; 27 | 28 | NSLog(@"MATEO userNotificationCenter didReceiveNotificationResponse"); 29 | if ([[AirPushNotification instance] isInitialized]) { 30 | // we can dispatch an event 31 | #if TARGET_OS_IPHONE 32 | [[AirPushNotification instance] trackRemoteNofiticationFromApp:[UIApplication sharedApplication] andUserInfo:notifDict]; 33 | #elif TARGET_OS_OSX 34 | [[AirPushNotification instance] trackRemoteNofiticationFromApp:[NSApplication sharedApplication] andUserInfo:notifDict]; 35 | #endif 36 | 37 | } else { 38 | // wait for it to be fetched 39 | self.starterNotif = notifDict; 40 | } 41 | 42 | 43 | // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 44 | // // handle the UNNotificationResponse 45 | // NSLog(@"MATEO userNotificationCenter didReceiveNotificationResponse completing after delay"); 46 | // completionHandler(); 47 | // }); 48 | completionHandler(); 49 | 50 | 51 | } 52 | 53 | - (void)userNotificationCenter:(UNUserNotificationCenter *)center 54 | willPresentNotification:(UNNotification *)notification 55 | withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler 56 | { 57 | 58 | NSLog(@"MATEO userNotificationCenter willPresentNotification"); 59 | if ([[AirPushNotification instance] isInitialized]) { 60 | #if TARGET_OS_IPHONE 61 | [[AirPushNotification instance] trackRemoteNofiticationFromApp:[UIApplication sharedApplication] andUserInfo:notification.request.content.userInfo]; 62 | #elif TARGET_OS_OSX 63 | [[AirPushNotification instance] trackRemoteNofiticationFromApp:[NSApplication sharedApplication] andUserInfo:notification.request.content.userInfo]; 64 | #endif 65 | 66 | } 67 | 68 | completionHandler(UNNotificationPresentationOptionNone); 69 | } 70 | 71 | -(void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification { 72 | 73 | if ([[AirPushNotification instance] isInitialized]) { 74 | // we can dispatch an event 75 | self.pendingOpenAppNotificationSettings = false; 76 | [[AirPushNotification instance] sendEvent:@"OPEN_APP_NOTIFICATION_SETTINGS"]; 77 | } else { 78 | // wait for ane initialized 79 | self.pendingOpenAppNotificationSettings = true; 80 | } 81 | } 82 | 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /ios/AirPushNotificationMac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2021 Freshplanet, Inc. All rights reserved. 23 | 24 | 25 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | platform :ios, '10.0' 3 | 4 | target 'AirPushNotification' do 5 | end 6 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODFILE CHECKSUM: 782bc6a46eb69c6f1b88ce9f6c856f24aca52952 2 | 3 | COCOAPODS: 1.5.3 4 | -------------------------------------------------------------------------------- /ios/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODFILE CHECKSUM: 782bc6a46eb69c6f1b88ce9f6c856f24aca52952 2 | 3 | COCOAPODS: 1.5.3 4 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Generated by CocoaPods - https://cocoapods.org 18 | Title 19 | 20 | Type 21 | PSGroupSpecifier 22 | 23 | 24 | StringsTable 25 | Acknowledgements 26 | Title 27 | Acknowledgements 28 | 29 | 30 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_AirPushNotification : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_AirPushNotification 5 | @end 6 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | install_framework() 10 | { 11 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 12 | local source="${BUILT_PRODUCTS_DIR}/$1" 13 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 14 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 15 | elif [ -r "$1" ]; then 16 | local source="$1" 17 | fi 18 | 19 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 20 | 21 | if [ -L "${source}" ]; then 22 | echo "Symlinked..." 23 | source="$(readlink "${source}")" 24 | fi 25 | 26 | # use filter instead of exclude so missing patterns dont' throw errors 27 | echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 28 | rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 29 | 30 | local basename 31 | basename="$(basename -s .framework "$1")" 32 | binary="${destination}/${basename}.framework/${basename}" 33 | if ! [ -r "$binary" ]; then 34 | binary="${destination}/${basename}" 35 | fi 36 | 37 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 38 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 39 | strip_invalid_archs "$binary" 40 | fi 41 | 42 | # Resign the code if required by the build settings to avoid unstable apps 43 | code_sign_if_enabled "${destination}/$(basename "$1")" 44 | 45 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 46 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 47 | local swift_runtime_libs 48 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 49 | for lib in $swift_runtime_libs; do 50 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 51 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 52 | code_sign_if_enabled "${destination}/${lib}" 53 | done 54 | fi 55 | } 56 | 57 | # Signs a framework with the provided identity 58 | code_sign_if_enabled() { 59 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 60 | # Use the current code_sign_identitiy 61 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 62 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'" 63 | 64 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 65 | code_sign_cmd="$code_sign_cmd &" 66 | fi 67 | echo "$code_sign_cmd" 68 | eval "$code_sign_cmd" 69 | fi 70 | } 71 | 72 | # Strip invalid architectures 73 | strip_invalid_archs() { 74 | binary="$1" 75 | # Get architectures for current file 76 | archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" 77 | stripped="" 78 | for arch in $archs; do 79 | if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then 80 | # Strip non-valid architectures in-place 81 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 82 | stripped="$stripped $arch" 83 | fi 84 | done 85 | if [[ "$stripped" ]]; then 86 | echo "Stripped $binary of architectures:$stripped" 87 | fi 88 | } 89 | 90 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 91 | wait 92 | fi 93 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -u 4 | set -o pipefail 5 | 6 | if [ -z ${UNLOCALIZED_RESOURCES_FOLDER_PATH+x} ]; then 7 | # If UNLOCALIZED_RESOURCES_FOLDER_PATH is not set, then there's nowhere for us to copy 8 | # resources to, so exit 0 (signalling the script phase was successful). 9 | exit 0 10 | fi 11 | 12 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 13 | 14 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 15 | > "$RESOURCES_TO_COPY" 16 | 17 | XCASSET_FILES=() 18 | 19 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 20 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 21 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 22 | 23 | case "${TARGETED_DEVICE_FAMILY:-}" in 24 | 1,2) 25 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 26 | ;; 27 | 1) 28 | TARGET_DEVICE_ARGS="--target-device iphone" 29 | ;; 30 | 2) 31 | TARGET_DEVICE_ARGS="--target-device ipad" 32 | ;; 33 | 3) 34 | TARGET_DEVICE_ARGS="--target-device tv" 35 | ;; 36 | 4) 37 | TARGET_DEVICE_ARGS="--target-device watch" 38 | ;; 39 | *) 40 | TARGET_DEVICE_ARGS="--target-device mac" 41 | ;; 42 | esac 43 | 44 | install_resource() 45 | { 46 | if [[ "$1" = /* ]] ; then 47 | RESOURCE_PATH="$1" 48 | else 49 | RESOURCE_PATH="${PODS_ROOT}/$1" 50 | fi 51 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 52 | cat << EOM 53 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 54 | EOM 55 | exit 1 56 | fi 57 | case $RESOURCE_PATH in 58 | *.storyboard) 59 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 60 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 61 | ;; 62 | *.xib) 63 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 64 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 65 | ;; 66 | *.framework) 67 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 68 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 69 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 70 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 71 | ;; 72 | *.xcdatamodel) 73 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" || true 74 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 75 | ;; 76 | *.xcdatamodeld) 77 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" || true 78 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 79 | ;; 80 | *.xcmappingmodel) 81 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" || true 82 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 83 | ;; 84 | *.xcassets) 85 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 86 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 87 | ;; 88 | *) 89 | echo "$RESOURCE_PATH" || true 90 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 91 | ;; 92 | esac 93 | } 94 | 95 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 96 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 97 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 98 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 99 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 100 | fi 101 | rm -f "$RESOURCES_TO_COPY" 102 | 103 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "${XCASSET_FILES:-}" ] 104 | then 105 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 106 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 107 | while read line; do 108 | if [[ $line != "${PODS_ROOT}*" ]]; then 109 | XCASSET_FILES+=("$line") 110 | fi 111 | done <<<"$OTHER_XCASSETS" 112 | 113 | if [ -z ${ASSETCATALOG_COMPILER_APPICON_NAME+x} ]; then 114 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 115 | else 116 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" --app-icon "${ASSETCATALOG_COMPILER_APPICON_NAME}" --output-partial-info-plist "${TARGET_TEMP_DIR}/assetcatalog_generated_info_cocoapods.plist" 117 | fi 118 | fi 119 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification.debug.xcconfig: -------------------------------------------------------------------------------- 1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 2 | OTHER_LDFLAGS = $(inherited) -ObjC 3 | PODS_BUILD_DIR = ${BUILD_DIR} 4 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 5 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 6 | PODS_ROOT = ${SRCROOT}/Pods 7 | -------------------------------------------------------------------------------- /ios/Pods/Target Support Files/Pods-AirPushNotification/Pods-AirPushNotification.release.xcconfig: -------------------------------------------------------------------------------- 1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 2 | OTHER_LDFLAGS = $(inherited) -ObjC 3 | PODS_BUILD_DIR = ${BUILD_DIR} 4 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 5 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 6 | PODS_ROOT = ${SRCROOT}/Pods 7 | --------------------------------------------------------------------------------