Android Parse push notification not working in Android - android

I'm trying to create a simple push notification application using parse, here is the code that I've used from the documentation:
package com.parse.starter;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseCrashReporting;
import com.parse.ParseUser;
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize Crash Reporting.
ParseCrashReporting.enable(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(this, "-", "-");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
Activity:
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
<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" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's 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" />
<application
android:name=".ParseApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:allowBackup="true">
<activity
android:name=".ParseStarterProjectActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
</application>
</manifest>
I try to send push notifications using the parse.com website console, but I dont receive anything in the app. Am I missing a part of the code?
EDIT: My package name is "com.parse.starter"!! its in AndroidManifest.xml

For whatever reason, Parse has two tutorials; one is complete and the other isn't. Guess which one you found.
The complete one is here:
https://www.parse.com/tutorials/android-push-notifications
Essentially, you are missing step 5. In your Application class, in the onCreate method...
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});

In your manifest it clearly says...
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's 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" />
and
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.parse.starter" />

Go to this parse create new application.Enter your application name and
click create app.
Then go to settings in that app.Copy your application id and client
key and paste it in your code.
Then you have to enable the Client push in settings->push.
Click Push->send a push ->Push Quick
Start->Android->Native(Java)->Existing Project->Then you have to
follow all the instructions placed in this Quick Start Link.
You have to add the parse 1.9.3 jar in File ->project structure ->App
->Dependencies-> + ->File Depency ->add the parse 1.9.3 jar.
The Application Class have to be like this:
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class Application extends android.app.Application {
public Application() {
}
#Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "", ""); //app id and client key
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Output:
You can see the verification here:

In your Application class, paste this:
Parse.initialize(this, "...", "...");
ParseInstallation.getCurrentInstallation().saveInBackground();
The 2nd line is missing. This is a similar solution to Murkaeus's answer.
Source: https://www.parse.com/apps/quickstart#parse_push/android/native/new

Related

Push Notification through local parse-server and parse dash board

Hi I am able to run parse-server and parse dashboard in my local system.I am trying to connect my android app to the parse -server which is also in same system.I am not hosting the parse-server to Heroku or any other Hosting site.I am able to get/send message from comandline using this command
curl -X POST \
-H "X-Parse-Application-Id:<App_ID>" \
-H "Content-Type: application/json" \
-d '{"Name":"<Name>","Score":<Score>}' \
http://localhost:1337/parse/classes/Player
But not able to connect the parse-server from my android app.
mongodb,parse-server-example and parse-dashboard is properly working.My Android code :
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.pushnotification" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="<my_Package>.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<my_Package>.permission.C2D_MESSAGE" />
<application
android:name=".PushParseServerTest"
android:allowBackup="true"
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>
<meta-data
android:name="com.parse.push.gcm_sender_id"
android:value="id:<gcm_project_id>" />
<service android:name="com.parse.PushService" />
<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" />
<category android:name="<my_package_name>" />
</intent-filter>
</receiver>
<receiver
android:name="<my_package>.ParsePushnotificationReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
<category android:name="<my_package_name>" />
</intent-filter>
</receiver>
</application>
</manifest>
Build.gradle file
{
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.parse.bolts:bolts-tasks:1.3.0'
compile 'com.parse:parse-android:1.13.0'
}
PushParseServerTest.java
public class StarterApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
//Parse.initialize(this);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("#string/parse_app_id")
.clientKey("#string/parse_client_key")
.server("http://<my_system_ip>:1337/parse/") // '/' important after 'parse'
.build());
}
}
ParsePushnotificationReceiver.java
public class ParsePushnotificationReceiver extends BroadcastReceiver {
private static final String TAG = "ParsePushnotificationReceiver";
// public static final String intentAction = "com.parse.push.intent.RECEIVE";
#Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
Log.d(TAG, "Receiver intent null");
} else {
// Parse push message and handle accordingly
Log.d(TAG, intent.getExtras().toString());
}
}
}
Is it an issue with push notifications or saving objects to parse-server?
Did you configure push notifications correctly on parse-server and register your android devices correctly?

Parse.com push notifications don't get to devices on background

Today I've implemented Parse.com Push service in my app.
I've noticed that the push notifications are being sent only when the app is open. I've also noticed that whenever I'm turning on my device there is a message says "Unfortunately, tof has stopped". The Logcat says Unable to start receiver.
The full Logcat:
java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2952)
at android.app.ActivityThread.access$1800(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
at com.parse.Parse.checkContext(Parse.java:440)
at com.parse.Parse.getApplicationContext(Parse.java:270)
at com.parse.ManifestInfo.getContext(ManifestInfo.java:324)
at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:328)
at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:358)
at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:446)
at com.parse.ManifestInfo.getPushType(ManifestInfo.java:212)
at com.parse.PushService.startServiceIfRequired(PushService.java:222)
at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2945)
at android.app.ActivityThread.access$1800(ActivityThread.java:172)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5832)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
I've tried to search on the Web but I didn't find any solution. I guess that it's something about the receiver background operation.
I need an answer as quickly as possible, so if you know a bit about Parse SDK and it's push topic so please, help me 'cause I need to solve this today.
This is my code.
MainActivity.java:
ParsePush parsePush = new ParsePush();
ParseQuery pQuery = ParseInstallation.getQuery(); // <-- Installation query
pQuery.whereEqualTo("username", User_Name);
parsePush.sendMessageInBackground(message, pQuery);
AndroidManifest.xml:
<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's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.intap.tof.permission.C2D_MESSAGE" />
<uses-permission android:name="com.intap.tof.permission.C2D_MESSAGE" />
...
<service android:name="com.parse.PushService" />
<receiver android:name="com.intap.tof.Receiver"
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's package name.
-->
<category android:name="com.intap.tof" />
</intent-filter>
</receiver>
I also have this line on Receiver.java:
package com.intap.tof;
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
I need major help right now!! Please help me!
Follow the steps below. This code works fine and run the receiver on background. The original answer link: https://www.parse.com/apps/quickstart#parse_push/android/native/existing
MainActivity.java file
public void onCreate() {
Parse.initialize(this, "APPLICATION ID", "CLIENT KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
AndroidManifest.xml file
<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's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
Permissions.
<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" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's 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" />
Have a look at this.
public class MainApplication extends Application {
private static MainApplication instance = new MainApplication();
public MainApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, " ", " ");
PushService.setDefaultPushCallback(this, FabulaClient.class);
PushService.subscribe(this, "Barca", FabulaClient.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
taken from https://www.parse.com/questions/cannot-send-push-to-android-after-app-is-closed-until-screen-unlock
I've understood why I don't get the push notifications on background.
I've initialized parse sdk twice - on the OpenActivity.java and on ParseApplication.java. I've removed it from the OpenActivity.java and added this code line:
android:name=".ParseApplication"
To the application attribute on the AndroidManifest.xml and now I can get push notifications on background.

Android push notifications not receiving/not sending

I know that this question has been asked a lot, but many also went unanswered.
However, I use Parse.com to send push-notifications to devices. On iOS it works fine. But it's not receives on Android devices.
When I looking at Push tab on service page I see that no one push wasn't sent. Value in 'Pushes Sent' column is 0 (zero).
Then I sent push through GCM (gcm-http.googleapis.com) and my device received the message.
Perhaps the problem may be in settings of Parse.com?
I was added Sender ID (Project number) & API Key from Google.
My AndroidManifest.xml immediately before the opening </application> tag:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="my.app.name.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my.app.name.permission.C2D_MESSAGE" />
My AndroidManifest.xml immediately before the closing </application> tag:
<meta-data android:name="com.parse.push.notification_icon" android:resource="#drawable/ic_stat_bt"/>
<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" />
<category android:name="my.app.name" />
</intent-filter>
</receiver>
My ApplicationClass
package my.app.name;
import android.util.Log;
import android.os.Bundle;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.SaveCallback;
import com.parse.ParseException;
public class MyApplication extends android.app.Application {
#Override
public void onCreate() {
super.onCreate();
// Parse
Parse.initialize(this, "", "");
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully installed.");
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
} else {
Log.e("com.parse.push", "failed to install", e);
}
}
});
}
...
On the advice of Clayton Oliveira I noticed, when I install my app and initialize it first time I get my token and pushes works fine. But when I open my app again I get another token and pushes are not working until I delete all data from Parse, uninstall my app & install it again.
Any ideas?
I was facing the same problem just now ! Here's what did the trick:
I uninstalled my app and deleted all the data previously stored on Parse (Installation, Session and User).
After that, just install your app again and if you did everything right from the Parse tutorial: https://www.parse.com/tutorials/android-push-notifications
Try send another Test Push ;)
If you do not add the permission of the message then add it in to your manifest file.
<uses-permission android:name="your.package.name.permission.C2D_MESSAGE"/>
and add this firebase lib in app's build.gradle file:
compile 'com.google.firebase:firebase-messaging:11.0.4'

Android + Phonegap + Parse Push keeps crashing

I've been trying to make a simple Phonegap app that receives Parse Push notifications on Android.
I've read a number of tutorials and read through related issues here and elsewhere but i can't seem to get it to work without crashing.
I have the latest of Java JDK, Cordova + Node JS + plugman, Android API 19 (seems to be required by cordova), Apache ant, etc...
Bottom line: I can start the app. I can receive the notification just fine. But when I tap the notification to go back to the app it always crashes.
Question? Can anyone explain why this is happening? Or even better if you have a sample project that works? Any help would be greatly appreciated.
References:
https://parse.com/tutorials/android-push-notifications
http://www.raymondcamden.com/2012/10/10/PhoneGap-Parsecom-and-Push-Notifications -- a bit out of date
How do I get Parse.com Push Notifications working in a Cordova/Phonegap Android app?
apache cordova app crashes after receiving parse.com push notification
Sources:
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.company.challenger" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<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.RECEIVE_BOOT_COMPLETED" />
<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" />
<permission android:name="com.company.challenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.challenger.permission.C2D_MESSAGE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:name="com.company.challenger.ChallengerApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/app_name" android:launchMode="singleTop" android:name="ChallengerApplication" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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.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="com.company.challenger" />
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.parse.ParsePushBroadcastReceiver">
<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>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
CordovaApp.java
package com.company.challenger;
import com.parse.ParseAnalytics;
import android.os.Bundle;
import org.apache.cordova.*;
public class CordovaApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
ParseAnalytics.trackAppOpened(getIntent());
}
}
ChallengerApplication.java
package com.company.challenger;
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
import com.company.challenger.CordovaApp;
public class ChallengerApplication extends Application
{
private static ChallengerApplication instance = new ChallengerApplication();
public ChallengerApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
#Override
public void onCreate() {
super.onCreate();
// register device for parse
Parse.initialize(this, "app key", "client key");
PushService.setDefaultPushCallback(this, CordovaApp.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Proper answer this time...
I basically started from scratch following the latest parse tutorial and making sure the initialize parse in the MainApplication and not in your javascript.
This is the gist:
Create a MainApplication.java with a skeleton like this:
package com.{your_company}.{your_app};
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParsePush;
import com.parse.SaveCallback;
import com.parse.ParseException;
import com.{your_company}.{your_app}.MainActivity;
public class MainApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
// parse initialization goes here
}
}
Add the following attribute to your application tag in AndroidManifest.xml
<application ... android:name="com.{your_company}.{your_app}.MainApplication">
Follow this tutorial from Parse.com which is fairly decent https://parse.com/tutorials/android-push-notifications .
The final onCreate in MainApplication.java should look something like this:
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(app);
Parse.initialize(app, "{app_key}", "{client_key}");
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
From this experience I found the following insights:
Not recommended to use any parse push plugins floating around because
there are all out of date using deprecated calls or simply did not
work out of the box.
The Parse initialize must occur in the MainApplication and cannot occur in the javascript. (I don't have the reference for this one, I came
across it somewhere down the line when frantically researching).
Always use the latest Parse SDK and use ParsePush (the new service) and not PushService which is depricated.
Hopefully this helps.

Unexpectedly Closed Application After Integration Parse.com

There was no problem while running my little android application. I integrated my application new feature. I am using real time push notification with using ready script by www.parse.com . There is no problem while running but when i closed screen and reopen .There is an error. Your application closed unexpectedly. I dont know why and there is no log.
I am using this code in my main activity before oncreate
Parse.initialize(this, "XXX", "YYY");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.islamiceducationquestions.v1"
android:versionCode="13"
android:versionName="8.0.1">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<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" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.islamiceducationquestions.v1.permission.C2D_MESSAGE" />
<uses-permission android:name="com.islamiceducationquestions.v1.permission.C2D_MESSAGE" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light.DarkActionBar">
<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>
<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.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's package name.
-->
<category android:name="com.islamiceducationquestions.v1" />
</intent-filter>
</receiver>
</application>
</manifest>
Log is :
java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2844)
at android.app.ActivityThread.access$1700(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at com.parse.Parse.checkContext(Parse.java:583)
at com.parse.Parse.getApplicationContext(Parse.java:191)
at com.parse.ManifestInfo.getContext(ManifestInfo.java:241)
at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:249)
at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:272)
at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:357)
at com.parse.ManifestInfo.getPushType(ManifestInfo.java:129)
at com.parse.PushService.startServiceIfRequired(PushService.java:150)
at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2833)
... 10 more
As you can see here Android Parse.com Simple ListView Tutorial you will need to call Parse.initialize from Application's onCreate instead of from Activity or Service. do it as:
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.initialize(this, YOUR_APPLICATION_ID, YOUR_CLIENT_KEY);
}
}
Also add ParseApplication in AndroidManifest.xml as application tag name:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:name="ParseApplication"
....

Categories

Resources