我正在尝试使用Parse推送Android通知,但应用程序崩溃。
这是我的代码
ParseApplication.java
:
public class ParseApplication extends Application{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Parse.initialize(this, "t9FCgoS4236bMVSZiXUWyzjX4pHMIThqRQA75Msh", "xNPNRx9su5iiAK8owJoozEK0Ft2cZenanCJ06Y3V");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
ParseReceiver.java
public class ParseReceiver extends BroadcastReceiver{
private final String TAG = "Parse Notification";
private String msg = "";
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.i(TAG, "PUSH RECEIVED!!!");
try {
String action = arg1.getAction();
String channel = arg1.getExtras().getString("com.parse.Channel");
JSONObject json = new J JSONObject(arg1.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
Log.d(TAG, "..." + key + " => " + json.getString(key));
if(key.equals("string")){
msg = json.getString(key);
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
Bitmap icon = BitmapFactory.decodeResource(arg0.getResources(),
R.drawable.happy);
Intent launchActivity = new Intent(arg0, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(arg0, 0, launchActivity, 0);
Notification noti = new NotificationCompat.Builder(arg0)
.setContentTitle("PUSH RECEIVED")
.setContentText(msg)
.setSmallIcon(R.drawable.happy)
.setLargeIcon(icon)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager nm = (NotificationManager)arg0.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
}
我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parse"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:name="com.example.parse.ParseApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name="com.example.parse.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>
<receiver android:name=".ParseReceiver" >
<intent-filter>
<action android:name="com.makemyandroidapp.parsenotificationexample.RECEIVE_PUSH" />
</intent-filter>
</receiver>
<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>
</application>
我的logcat:
04-25 09:53:49.754: I/dalvikvm(370): Could not find method com.parse.Parse.initialize, referenced from method c com.example.parse.ParseApplication.onCreate
04-25 09:53:49.784: W/dalvikvm(370): VFY: unable to resolve static method 43: Lcom/parse/Parse;.initialize (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
04-25 09:53:49.784: D/dalvikvm(370): VFY: replacing opcode 0x71 at 0x0007
04-25 09:53:49.804: D/AndroidRuntime(370): Shutting down VM
04-25 09:53:49.804: W/dalvikvm(370): threadid=1: thread exiting with uncaught exception (group=0x40014760)
04-25 09:53:49.905: E/AndroidRuntime(370): FATAL EXCEPTION: main
04-25 09:53:49.905: E/AndroidRuntime(370): java.lang.NoClassDefFoundError: com.parse.Parse
04-25 09:53:49.905: E/AndroidRuntime(370): at com.example.parse.ParseApplication.onCreate(ParseApplication.java:16)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:968)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3580)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1031)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.os.Looper.loop(Looper.java:126)
04-25 09:53:49.905: E/AndroidRuntime(370): at android.app.ActivityThread.main(ActivityThread.java:3997)
04-25 09:53:49.905: E/AndroidRuntime(370): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 09:53:49.905: E/AndroidRuntime(370): at java.lang.reflect.Method.invoke(Method.java:491)
04-25 09:53:49.905: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-25 09:53:49.905: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-25 09:53:49.905: E/AndroidRuntime(370): at dalvik.system.NativeStart.main(Native Method)
04-25 09:53:57.356: I/Process(370): Sending signal. PID: 370 SIG: 9
我该如何解决这个问题?
答案 0 :(得分:0)
检查您的依赖项,并确保您正在为项目编译Parse。