9
1. 2. 3. 1. 2. 3. Android Getting Started Using push notifications in the Android platform enables you to send interactive notifications to your app users. You can modify the notification parameters, it's visualisation and much more. Setup an Android project in the Google Cloud Console Configure your app in the PushApps Admin Console Integrate the SDK into your app Setup an Android project in the Google Cloud Console Open the Google Cloud Console. Create an API project by clicking . CREATE PROJECT Once the project that has been created. a page appears that displays your project ID and the project number. For example here, Project Number: 449866648164. Please Notice If you are testing on an emulator - set the target of the emulator to Google APIs Notice: In order to create a new project you will need the 'is owner' permission in the Google Cloud Console. If you don't have please contact the account administrator and ask for the permission or ask him/her to create the project.

Android Push Notifications with PushApps

Embed Size (px)

Citation preview

Page 1: Android Push Notifications with PushApps

1. 2. 3.

1. 2.

3.

Android Getting StartedUsing push notifications in the Android platform enables you to send interactive notifications to your app users. You can modify the notificationparameters, it's visualisation and much more.

Setup an Android project in the Google Cloud ConsoleConfigure your app in the PushApps Admin ConsoleIntegrate the SDK into your app

Setup an Android project in the Google Cloud ConsoleOpen the Google Cloud Console.Create an API project by clicking  .CREATE PROJECT

Once the project that has been created. a page appears that displays your project ID and the project number. For example here,Project Number: 449866648164.

Please NoticeIf you are testing on an emulator - set the target of the emulator to Google APIs

Notice: In order to create a new project you will need the 'is owner' permission in the Google Cloud Console. If youdon't have please contact the account administrator and ask for the permission or ask him/her to create the project.

Page 2: Android Push Notifications with PushApps

3.

4.

5.

 To enable the GCM service, in the sidebar on the left, select  , and In the displayed list of APIs, turn the APIs & auth Google Cloud

toggle to ON.Messaging for Android 

In  the  section, you will see a list of your existing credentials.Credentials  

Notice: The project number generated by Google, is the is the GOOGLE_API_PROJECT_ID that you need you need tosupply in the SDK

Page 3: Android Push Notifications with PushApps

5.

6.

7.

Under the  click on  , and a  dialog will appear, there select the   optioPublic API Access  Create new key 'Create a new key'  Browser keyn.

In the following dialog click on  .Create

Page 4: Android Push Notifications with PushApps

7.

8.

1.

Now you have created a  , it should appear in the  sections next to  the  as in the following screenshot.Browser key Credentials     API keythe  is used as the   in  .Browser key  GCM API Key PushApps

 

Configure your app in the PushApps admin consoleLogin to the  , go to  , choose the relevant app and go to   and click on PushApps Admin Console My Apps Settings > Manage Platforms C

 by the Android icon. Type your API key.onfigure

Page 5: Android Push Notifications with PushApps

1.

2.

1. 2.

After pressing the save button, the Android icon will become green.

 

Integrate the SDK into your appDownload the SDK from the  .PushApps GITHUB repositoryAdd the   file to your project's   folder. If you use Eclipse, then you should see the   in the project propertiespushapps.jar libs pushapps.jar> java build path > Libraries > Android Private Libraries;

Page 6: Android Push Notifications with PushApps

2.

If the   does not exists then you need to add it by clicking on :pushapps.jar  Add JARs

Page 7: Android Push Notifications with PushApps

2.

3. In your main activity, inside the method onCreate(), add the PushApps init line:

Page 8: Android Push Notifications with PushApps

3.

4.

5.

import com.groboot.pushapps.PushManager;import android.app.Activity;import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Start PushApps and register to the push notification service (GCM) PushManager.init(getApplicationContext(), GOOGLE_API_PROJECT_ID,PUSHAPPS_APP_TOKEN); //optional - allows more than on notifications in the status bar, defaultis false PushManager.getInstance(getApplicationContext()).setShouldStackNotifications(true); //optional - set a your own icon for the notification, defaults is theapplication icon PushManager.getInstance(getApplicationContext()).setNotificationIcon(R.drawable.notification_icon); // optional - sets the source of the device id for identification,default is DeviceIDTypes.IMEI PushManager.getInstance(getApplicationContext()).setDeviceIDType(DeviceIDTypes.ANDROID_ID); }}

For further explanation and more options regarding the sdk please refer to the  .Android ReferenceAdd the following permissions to your file:AndroidManifest.xml

Add the following receiver, service and activity, inside your tag in the :application AndroidManifest.xml

 

NoticeYou need to replace the GOOGLE_API_PROJECT_ID, and the PUSHAPPS_APP_TOKEN with yours.

 <permission android:name="<your package>.permission.C2D_MESSAGE" android:protectionLevel="signature" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.VIBRATE" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android:name="android.permission.GET_ACCOUNTS" /><uses-permission android:name="android.permission.WAKE_LOCK" /><uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /><uses-permission android:name="<your package>.permission.C2D_MESSAGE" />

NoticeReplace <your package> markup with your package name, e.g: com.pushapps.demo.

Page 9: Android Push Notifications with PushApps

5.

<receiver android:name="com.groboot.pushapps.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="<your package>" /> </intent-filter></receiver> <service android:name="com.groboot.pushapps.GCMBaseIntentServiceImpl" /> <activity android:name="com.groboot.pushapps.PushActivity" android:configChanges="orientation|keyboardHidden" />