Created
July 26, 2017 01:27
-
-
Save MotiurRahman/5f8caad78cea4874096903094830a2c5 to your computer and use it in GitHub Desktop.
Alloy Push notification Test in Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ti.App.Cloud = require("ti.cloud"); | |
Ti.App.CloudPush = require('ti.cloudpush'); | |
Ti.App.CloudPush.enabled = true; | |
Ti.App.CloudPush.showTrayNotification = true; | |
Ti.App.CloudPush.showTrayNotificationsWhenFocused = true; | |
Ti.App.CloudPush.focusAppOnPush = false; | |
Ti.App.CloudPush.singleCallback = true; | |
Ti.App.CloudPush.addEventListener('callback', function(evt) { | |
alert(evt.payload); | |
}); | |
Ti.App.CloudPush.addEventListener('trayClickLaunchedApp', function(evt) { | |
alert('Tray Click Launched App (app was not running)'); | |
}); | |
Ti.App.CloudPush.addEventListener('trayClickFocusedApp', function(evt) { | |
alert('Tray Click Focused App (app was already running)'); | |
}); | |
function doClick(e) { | |
Ti.App.CloudPush.retrieveDeviceToken({ | |
success : function(e) { | |
Ti.API.warn('ENABLE PUSH NOTIFICATION SUCCESS: ' + e.deviceToken); | |
Ti.App.Cloud.PushNotifications.subscribeToken({ | |
device_token : e.deviceToken, | |
channel : 'test', | |
type : 'android' | |
}, function(e) { | |
if (e.success) { | |
alert("Device has been Subscribed"); | |
} else { | |
Ti.API.warn('ENABLE PUSH NOTIFICATION ERROR: ' + e); | |
} | |
}); | |
}, | |
error : function(e) { | |
Ti.API.warn('ENABLE PUSH NOTIFICATION ERROR: ' + e.error); | |
} | |
}); | |
} | |
function menuClick() { | |
Alloy.createController('nextWin').getView().open(); | |
} | |
$.index.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window class="container"> | |
<Label id="label" onClick="doClick">Subscribe</Label> | |
<Label id="label" onClick="menuClick">Go to Next</Label> | |
</Window> | |
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var args = $.args; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window class="container"> | |
<Label id="label">Menu</Label> | |
</Window> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment