Permalink
Browse files

Initial Submit

  • Loading branch information...
0 parents commit 63b67c2866f0c3afda8e374dd6571b06e91b9850 @awysocki committed Jun 3, 2011
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="lib" path="libs/phonegap.0.9.5.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Android-C2DM-PhoneGap</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.phonegap.c2dm"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <supports-screens
+ android:largeScreens="true"
+ android:normalScreens="true"
+ android:smallScreens="true"
+ android:resizeable="true"
+ android:anyDensity="true"
+ />
+ <uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.VIBRATE" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.RECEIVE_SMS" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
+ <!-- START:C2DM messaging stuff -->
+ <uses-library android:name="com.google.android.c2dm.C2DMessaging" />
+
+ <permission android:name="com.phonegap.c2dm.permission.C2D_MESSAGE"
+ android:protectionLevel="signature" />
+ <uses-permission android:name="com.phonegap.c2dm.permission.C2D_MESSAGE" />
+
+ <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
+
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <!-- END:C2DM messaging stuff -->
+
+
+
+
+
+ <uses-sdk android:minSdkVersion="8" />
+
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".App"
+ android:configChanges="orientation|keyboardHidden"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+
+ <!-- START:C2DM messaging stuff -->
+ <service android:name=".C2DMReceiver" />
+
+ <!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it -->
+ <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
+ <!-- Receive the actual message -->
+ <intent-filter>
+ <action android:name="com.google.android.c2dm.intent.RECEIVE" />
+ <category android:name="com.phonegap.c2dm" />
+ </intent-filter>
+ <!-- Receive the registration id -->
+ <intent-filter>
+ <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
+ <category android:name="com.phonegap.c2dm" />
+ </intent-filter>
+ </receiver>
+ <!-- END:C2DM messaging stuff -->
+
+
+
+
+ </application>
+</manifest>
@@ -0,0 +1,60 @@
+
+/**
+ *
+ * @return Instance of C2DM
+ */
+var C2DM = function() {
+
+}
+
+/**
+ *
+ *
+ *
+ */
+C2DM.prototype.register = function(senderEmail, eventCallback, successCallback, failureCallback) {
+
+ if ( typeof eventCallback != "string") // The eventCallback has to be a STRING name not the actual routine like success/fail routines
+ {
+ var e = new Array();
+ e.msg = 'eventCallback must be a STRING name of the routine';
+ e.rc = -1;
+ failureCallback( e );
+ return;
+ }
+
+ return PhoneGap.exec(successCallback, //Callback which will be called when directory listing is successful
+ failureCallback, //Callback which will be called when directory listing encounters an error
+ 'C2DMPlugin', //Telling PhoneGap that we want to run "DirectoryListing" Plugin
+ 'register', //Telling the plugin, which action we want to perform
+ [{ email: senderEmail, ecb : eventCallback }]); //Passing a list of arguments to the plugin,
+ // The ecb variable is the STRING name of your javascript routine to be used for callbacks
+ // You can add more to validate that eventCallback is a string and not an object
+};
+
+
+C2DM.prototype.unregister = function( successCallback, failureCallback ) {
+
+
+ return PhoneGap.exec(successCallback, //Callback which will be called when directory listing is successful
+ failureCallback, //Callback which will be called when directory listing encounters an error
+ 'C2DMPlugin', //Telling PhoneGap that we want to run "DirectoryListing" Plugin
+ 'unregister', //Telling the plugin, which action we want to perform
+ [{ }]); //Passing a list of arguments to the plugin,
+};
+
+
+
+/**
+ */
+
+
+PhoneGap.addConstructor(function() {
+ //Register the javascript plugin with PhoneGap
+ PhoneGap.addPlugin('C2DM', new C2DM());
+
+ //Register the native class of plugin with PhoneGap
+ PluginManager.addService("C2DMPlugin","com.plugin.C2DM.C2DMPlugin");
+
+ //alert( "added Service C2DMPlugin");
+});
@@ -0,0 +1,126 @@
+//alert( localStorage.site );
+gApp = new Array();
+
+gApp.deviceready = false;
+gApp.c2dmregid = '';
+
+window.onbeforeunload = function(e) {
+
+ if ( gApp.c2dmregid.length > 0 )
+ {
+ // The same routines are called for success/fail on the unregister. You can make them unique if you like
+ window.plugins.C2DM.unregister( C2DM_Success, C2DM_Fail ); // close the C2DM
+
+ }
+};
+
+
+
+//$(document).bind("mobileinit", function() {
+
+ $("#app-status-ul").append( '<li>Mobileinit event received' );
+
+ document.addEventListener('deviceready', function() {
+ // This is the PhoneGap deviceready event. Once this is called PhoneGap is available to be used
+ $("#app-status-ul").append( '<li>deviceready event received' );
+
+ $("#app-status-ul").append( '<li>calling C2DM.register, register our email with Google' );
+
+
+ gApp.DeviceReady = true;
+
+ // Some Unique stuff here,
+ // The first Parm is your Google email address that you were authorized to use C2DM with
+ // the Event Processing rountine (2nd parm) we pass in the String name
+ // not a pointer to the routine, under the covers a JavaScript call is made so the name is used
+ // to generate the function name to call. I didn't know how to call a JavaScript routine from Java
+ // The last two parms are used by PhoneGap, they are the callback routines if the call is successful or fails
+ //
+ // CHANGE: your_c2dm_account@gmail.com
+ // TO: what ever your C2DM authorized email account name is
+ //
+ window.plugins.C2DM.register("your_c2dm_account@gmail.com", "C2DM_Event", C2DM_Success, C2DM_Fail );
+
+ }, false );
+
+
+//});
+
+function
+C2DM_Event(e)
+{
+ var li = '';
+ li = '<li>EVENT -> RECEIVED:' + e.event;
+ $("#app-status-ul").append( li )
+
+ switch( e.event )
+ {
+ case 'registered':
+ // the definition of the e variable is json return defined in C2DMReceiver.java
+ // In my case on registered I have EVENT and REGID defined
+ gApp.c2dmregid = e.regid;
+ if ( gApp.c2dmregid.length > 0 )
+ {
+ li = '<li>REGISTERED -> REGID:' + e.regid;
+ $("#app-status-ul").append( li )
+
+ // ==============================================================================
+ // ==============================================================================
+ // ==============================================================================
+ //
+ // This is where you would code to send the REGID to your server for this device
+ //
+ // ==============================================================================
+ // ==============================================================================
+ // ==============================================================================
+
+ }
+
+ break
+
+ case 'message':
+ // the definition of the e variable is json return defined in C2DMReceiver.java
+ // In my case on registered I have EVENT, MSG and MSGCNT defined
+
+ // You will NOT receive any messages unless you build a HOST server application to send
+ // Messages to you, This is just here to show you how it might work
+
+ li = '<li>MESSAGE -> MSG:' + e.msg;
+ $("#app-status-ul").append( li )
+ li = '<li>MESSAGE -> MSGCNT:' + e.msgcnt;
+ $("#app-status-ul").append( li )
+
+ break;
+
+
+ case 'error':
+
+ li = '<li>ERROR -> MSG:' + e.msg;
+ $("#app-status-ul").append( li )
+ break;
+
+
+
+ default:
+ li = '<li>EVENT -> Unknown, an event was received and we do not know what it is';
+ $("#app-status-ul").append( li )
+ break;
+ }
+}
+
+function
+C2DM_Success(e)
+{
+ li = '<li>C2DM_Success -> We have successfully registered and called the C2DM plugin, waiting for C2DM_Event:reistered -> REGID back from Google';
+ $("#app-status-ul").append( li )
+}
+
+function
+C2DM_Fail(e)
+{
+ li = '<li>C2DM_Fail -> C2DM plugin failed to register';
+ $("#app-status-ul").append( li )
+ li = '<li>C2DM_Fail -> ' + e.msg;
+ $("#app-status-ul").append( li )
+}
+
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>com.PhoneGap.c2dm</title>
+<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
+<script src="C2DMPlugin.js"></script> <!-- C2DM Phone Gap plugin -->
+<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
+
+<!-- Include my Javascript routines -->
+<script type="text/javascript" charset="utf-8" src="PG_C2DM_script.js"></script>
+</head>
+<body>
+ <div id="app-status-div">
+ <ul id="app-status-ul">
+ <li>Welcome
+ <li>PhoneGap routine built using <BR><a href="http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html">Lars Vogel<BR>
+ Android Cloud to Device Messaging (C2DM) - Tutorial </a>
+ </ul>
+ </div>
+</body>
+</html>

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 63b67c2

Please sign in to comment.