How to register my Android app to parse a site
Here's the best way to implement the official Parse SDK for standard push notification based on my experiences and some trial and error as well as many SO and Parse threads . So I'll go through these steps:
-
Add the following dependencies to your app's build.gradle file and you can get the latest versions from empty parse github projects or Parse SDK from docs on website. the latest versions are still here:
compile 'com.parse.bolts:bolts-tasks:1.3.0' compile 'com.parse:parse-android:1.11.0'
-
Add the following codes similar to the quick reference guide in the method of application class
onCreate()
project, change the appropriate keys → Note that these two lines should be added aftersuper.onCreate();
:// Enable Local Datastore. Parse.enableLocalDatastore(this); // Add your initialization code here Parse.initialize(this, "YOUR APPLICATION ID", "YOUR CLIENT KEY"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); // Optionally enable public read access. // defaultACL.setPublicReadAccess(true); ParseACL.setDefaultACL(defaultACL, true);
-
Add the following line after
setContentView
to the MainActivity class:ParseAnalytics.trackAppOpenedInBackground(getIntent());
-
add the Parse service and receivers to AndroidManifest.xml just before the closing tag
</application>
and make the specified package names identical to yours:<service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false"> <intent-filter> <action android:name="com.parse.push.intent.RECEIVE" /> <action android:name="com.parse.push.intent.DELETE" /> <action android:name="com.parse.push.intent.OPEN" /> </intent-filter> </receiver> <receiver android:name="com.parse.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" /> <!-- IMPORTANT: Change "com.parse.starter" to match your app package name. --> <category android:name="com.parse.starter" /> </intent-filter> </receiver>
-
add permissions like the instructions in the quickstart, usually just before the opening tag
<application>
, and make the specified package names the same as yours:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below to match your app package name + ".permission.C2D_MESSAGE". --> <permission android:protectionLevel="signature" android:name="com.parse.starter.permission.C2D_MESSAGE" /> <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
LAST STEP) Well done! Enjoy pushing your stuff. ;)
source to share
Add the following code to your manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="${your_application_package}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${your_application_package}.permission.C2D_MESSAGE" />
<application
android:name="${your_application_package}.ParseApplication"
android:allowBackup="true"
android:icon="@drawable/contact_image"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Parse library -->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app package name. -->
<category android:name="${your_application_package}" />
</intent-filter>
</receiver>
Your ParseApplication should look like this
public class ParseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//TODO: replace application_id and ClientKey with your parse credentials
Parse.initialize(this, "application_id", "ClientKey");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Add the bolts-android-1.2.0 and Parse-1.9.2 libraries to your project. Now run the application and check in parse dashborad that you will register your device.
source to share
just now i downloaded a sample push app from a parsing site ... and this downloaded solution will implement 2 projects ... 1 for ios and 1 for android ... ios wont push directly ... so we need to do our android project as a launch project and we need to launch our app ... so that your phone detects your parsing site and goes to the tab in the control panel and select send push ... there in the text box write what information you want click and click "Submit Now ..." for push information to appear on your mobile phone.
source to share