-
Notifications
You must be signed in to change notification settings - Fork 0
Push messaging on Android #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmihal
wants to merge
17
commits into
master
Choose a base branch
from
android
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f1c4513
Register for GCM messages and get device key
dmihal a47c45a
Set up module to build on Android
dmihal d1afd07
Update service to display notifications
dmihal fc43db9
Change incorrect event name
dmihal ef3156d
Add more instructions to build steps
dmihal 5d833e9
Remove .trigger folder, should be ignored
dmihal 3a563e1
Restructure project to make more trigger.io friendly
dmihal 65940b9
Remove inspector-config.json from repo, should be ignored
dmihal 33486d5
Remove newer android-support-v4 lib, change WakefulBroadcastReciever …
dmihal 04f0e7c
Update version number
dmihal 7a1853a
1.0.9: Parse notification JSON
dmihal 411a183
Refactor Notification->PushMessage to avoid conflict. Tapping notific…
dmihal 1d26fcb
Merge branch 'master' into android
dmihal 1ee1f7f
GCM ID set in module configuration, so string value not needed
dmihal f1ca25c
Hide notifications after they are tapped
dmihal 2696648
Remove repeated logic
dmihal 9c083be
Fix indentation
dmihal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/API.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package io.trigger.forge.android.modules.push; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.google.android.gms.gcm.GoogleCloudMessaging; | ||
| import com.google.gson.JsonPrimitive; | ||
|
|
||
| import io.trigger.forge.android.core.ForgeApp; | ||
| import io.trigger.forge.android.core.ForgeTask; | ||
|
|
||
| public class API { | ||
|
|
||
| private static boolean isRegistered = false; | ||
|
|
||
| public static void registerWithAPNS(final ForgeTask task){ | ||
| final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(ForgeApp.getApp()); | ||
| try { | ||
| String senderID = ForgeApp.configForPlugin("push").get("gcm-sender-id").getAsString(); | ||
| //TODO: the register method is deprecated | ||
| String regid = gcm.register(senderID); | ||
| isRegistered = true; | ||
| task.success(regid); | ||
| ForgeApp.event("onDidRegisterWithAPNS", new JsonPrimitive(regid)); | ||
| } catch (IOException e) { | ||
| task.error(e.getMessage()); | ||
| } | ||
| } | ||
| public static void checkIfRegisteredWithAPNS(final ForgeTask task){ | ||
| task.success(isRegistered); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...tor/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/EventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.trigger.forge.android.modules.push; | ||
|
|
||
| import io.trigger.forge.android.core.ForgeApp; | ||
| import io.trigger.forge.android.core.ForgeEventListener; | ||
|
|
||
| public class EventListener extends ForgeEventListener { | ||
|
|
||
| @Override | ||
| public void onRestart() { | ||
| ForgeApp.event("push.resume", null); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...ector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMReceiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package io.trigger.forge.android.modules.push; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.BroadcastReceiver; | ||
| import android.content.ComponentName; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
|
|
||
| public class GCMReceiver extends BroadcastReceiver { | ||
|
|
||
| @Override | ||
| public void onReceive(Context context, Intent intent) { | ||
| ComponentName comp = new ComponentName(context.getPackageName(), GCMService.class.getName()); | ||
| context.startService(intent.setComponent(comp)); | ||
| setResultCode(Activity.RESULT_OK); | ||
| } | ||
|
|
||
| } |
55 changes: 55 additions & 0 deletions
55
inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.trigger.forge.android.modules.push; | ||
|
|
||
| import io.trigger.forge.android.core.ForgeApp; | ||
|
|
||
| import android.util.Log; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonPrimitive; | ||
| import com.google.gson.JsonSyntaxException; | ||
| import com.kinvey.android.push.KinveyGCMService; | ||
|
|
||
| public class GCMService extends KinveyGCMService { | ||
|
|
||
| private static final Gson gson = new Gson(); | ||
|
|
||
| @Override | ||
| public Class getReceiver() { | ||
| return GCMReceiver.class; | ||
| } | ||
|
|
||
| @Override | ||
| public void onDelete(String arg0) { | ||
| Log.i(TAG, arg0); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(String arg0) { | ||
| Log.e(TAG, arg0); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMessage(String message) { | ||
| PushMessage notification; | ||
| try { | ||
| notification = gson.fromJson(message, PushMessage.class); | ||
| } catch (JsonSyntaxException e) { | ||
| notification = new PushMessage(message); | ||
| } | ||
| notification.show(); | ||
| ForgeApp.event("push.message", new JsonPrimitive(message)); | ||
| } | ||
|
|
||
| @Override | ||
| public void onRegistered(String arg0) { | ||
| Log.i(TAG, arg0); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onUnregistered(String arg0) { | ||
| Log.i(TAG, arg0); | ||
|
|
||
| } | ||
|
|
||
| } |
60 changes: 60 additions & 0 deletions
60
...ector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/PushMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package io.trigger.forge.android.modules.push; | ||
|
|
||
| import io.trigger.forge.android.core.ForgeApp; | ||
| import android.app.Notification; | ||
| import android.app.NotificationManager; | ||
| import android.app.PendingIntent; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.support.v4.app.NotificationCompat; | ||
|
|
||
| public class PushMessage { | ||
|
|
||
| private String message; | ||
| private String from; | ||
| private String subject; | ||
|
|
||
|
|
||
| public PushMessage(String message) { | ||
| this(message, "Fetchnotes", ""); | ||
| } | ||
| public PushMessage(String message, String from, String subject) { | ||
| this.message = message; | ||
| this.from = from; | ||
| this.subject = subject; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| public void setMessage(String message) { | ||
| this.message = message; | ||
| } | ||
| public String getFrom() { | ||
| return from; | ||
| } | ||
| public void setFrom(String from) { | ||
| this.from = from; | ||
| } | ||
| public String getSubject() { | ||
| return subject; | ||
| } | ||
| public void setSubject(String subject) { | ||
| this.subject = subject; | ||
| } | ||
| public void show() { | ||
| Context context = ForgeApp.getApp(); | ||
| Intent intent = new Intent(context, ForgeApp.getActivity().getClass()); | ||
| PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | ||
| NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) | ||
| .setSmallIcon(ForgeApp.getResourceId("icons", "drawable")) | ||
| .setDefaults(Notification.DEFAULT_VIBRATE) | ||
| .setContentIntent(pendingIntent) | ||
| .setAutoCancel(true) | ||
| .setContentTitle(from) | ||
| .setContentText(message); | ||
| NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
| mNotificationManager.notify(1, mBuilder.getNotification()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| [ | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "android.permission.INTERNET" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "android.permission.ACCESS_NETWORK_STATE" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "android.permission.VIBRATE" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "android.permission.WAKE_LOCK" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "com.google.android.c2dm.permission.RECEIVE" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "android.permission.BROADCAST_STICKY" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_to_application_manifest": { | ||
| "element": { | ||
| "tag": "permission", | ||
| "attributes": { | ||
| "android:name": "io.trigger.forge.android.modules.push.permission.C2D_MESSAGE", | ||
| "android:protectionLevel": "signature" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_permission": { | ||
| "permission": "io.trigger.forge.android.modules.push.permission.C2D_MESSAGE" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_to_application_manifest": { | ||
| "element": { | ||
| "tag": "receiver", | ||
| "attributes": { | ||
| "android:name": "io.trigger.forge.android.modules.push.GCMReceiver", | ||
| "android:permission": "com.google.android.c2dm.permission.SEND" | ||
| }, | ||
| "children": [{ | ||
| "tag": "intent-filter", | ||
| "children": [{ | ||
| "tag": "action", | ||
| "attributes": { | ||
| "android:name": "com.google.android.c2dm.intent.RECEIVE" | ||
| } | ||
| }, { | ||
| "tag": "action", | ||
| "attributes": { | ||
| "android:name": "com.google.android.c2dm.intent.REGISTRATION" | ||
| } | ||
| }, { | ||
| "tag": "category", | ||
| "attributes": { | ||
| "android:name": "io.trigger.forge.android.modules.push" | ||
| } | ||
| }] | ||
| }] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_to_application_manifest": { | ||
| "element": { | ||
| "tag": "service", | ||
| "attributes": { | ||
| "android:name": "io.trigger.forge.android.modules.push.GCMService", | ||
| "android:label": "Push Notification Service" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_to_application_manifest": { | ||
| "element": { | ||
| "tag": "meta-data", | ||
| "attributes": { | ||
| "android:name": "com.google.android.gms.version", | ||
| "android:value": "@integer/google_play_services_version" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_proguard_rule": { | ||
| "rule": "-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); }" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_proguard_rule": { | ||
| "rule": "-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; }" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_proguard_rule": { | ||
| "rule": "-keepnames @com.google.android.gms.common.annotation.KeepName class *" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_proguard_rule": { | ||
| "rule": "-keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; }" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "do": { | ||
| "android_add_proguard_rule": { | ||
| "rule": "-keepnames class * implements android.os.Parcelable { public static final ** CREATOR; }" | ||
| } | ||
| } | ||
| } | ||
| ] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <integer name="google_play_services_version">7571000</integer> | ||
| </resources> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove repeated logic?