Last active
October 18, 2017 22:06
-
-
Save ToeJamson/a9eb6b122e92b370372b to your computer and use it in GitHub Desktop.
Build an Android mobile Chat App with PhoneGap & Cordova
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
$ npm install -g cordova |
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
$rootScope.$on(PubNub.ngPrsEv($scope.channel), function(ngEvent, payload) { | |
$scope.$apply(function() { | |
$scope.users = PubNub.ngListPresence($scope.channel); | |
}); | |
}); |
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
PubNub.ngHereNow({ | |
channel: $scope.channel | |
}); | |
PubNub.ngHistory({ | |
channel: $scope.channel, | |
count: 500 | |
}); |
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
$scope.publish = function() { | |
PubNub.ngPublish({ | |
channel: $scope.channel, | |
message: "[" + $scope.userId + "] " + $scope.newMessage | |
}); | |
$scope.newMessage = ''; | |
}; |
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
$ cordova platform add android | |
$ cordova build 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
$ cordova emulate 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
$ adb install {project_root}/platforms/android/ant-build/CordovaApp_debug.apk |
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
$ brew update | |
$ brew install ant |
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
export ANDROID_HOME={path/to/android/sdk}/ | |
export ANDROID_TOOLS={path/to/android/sdk}/tools/ | |
export ANDROID_PLATFORM_TOOLS={path/to/android/sdk}/platform-tools/ | |
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS:. |
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
$ cordova create [folder name] [com.example.appname] [application name] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="format-detection" | |
content="telephone=no" /> | |
<meta name="msapplication-tap-highlight" | |
content="no" /> | |
<meta name="viewport" | |
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> | |
<!-- Required libraries for the chat --> | |
<script src="https://cdn.pubnub.com/pubnub.min.js"></script> | |
<script src="https://cdn.pubnub.com/pubnub-crypto.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> | |
<script src="http://pubnub.github.io/pubnub-angular/lib/pubnub-angular.js"></script> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<title>PubNub Angular Mobile Chat</title> | |
</head> |
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
<body> | |
<div class="container" ng-app="PubNubAngularApp" ng-controller="ChatCtrl"> | |
<br /> | |
<h4>Online Users</h4> | |
<ul> | |
<li ng-repeat="user in users">{{user}}</li> | |
</ul> | |
<br /> | |
<h4>Chat History ({{messages.length}})</h4> | |
<form ng-submit='publish()'> | |
<input type="text" ng-model='newMessage' /> | |
<input type="submit" value="Send" /> | |
</form> | |
<br /> | |
<div class="well"> | |
<ul> | |
<li ng-repeat="message in messages">{{message}}</li> | |
</ul> | |
</div> | |
</div> | |
<script type="text/javascript" src="cordova.js"></script> | |
<script type="text/javascript" src="js/pubnubAngularApp.js"></script> | |
</body> | |
</html> |
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
PubNub.init({ | |
subscribe_key: 'pubnub subscribe key here', | |
publish_key: 'pubnub publish key here', | |
uuid:$scope.userId | |
}); |
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
PubNub.ngSubscribe({ channel: $scope.channel }); |
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
$rootScope.$on(PubNub.ngMsgEv($scope.channel), function(ngEvent, payload) { | |
scope.$apply(function() { | |
$scope.messages.push(payload.message); | |
}); | |
}); |
dsfdsf
dsfffdsfds
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dsfds