簡體   English   中英

嘗試運行parse.com推送通知應用程序時,應用程序崩潰

[英]App crashes when trying to run parse.com push notification application

每當我運行它時,我的解析推送通知應用程序就會崩潰。 我仔細檢查以確保權限正確,並且我的build.gradle也正確。 我為Parse Application創建了一個Java類(添加到src文件夾中)。 這是解析應用程序,我的Android清單和build.gradle文件的代碼。

建檔文件

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.anish.parseexample"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/Parse-1.9.2.jar')
}

PARSEAPP.JAVA

 package com.example.anish.parseexample;

 import android.app.Application;

 import com.parse.Parse;
 import com.parse.PushService;

 public class ParseApp extends Application {
 @Override
 public void onCreate() {
    super.onCreate();
    Parse.initialize(this, "APP_ID_KEY_WAS_HERE", "CLIENT_ID_KEY_WAS_HERE");
    PushService.setDefaultPushCallback(this, MainActivity.class);
}
}

ANDROIDMANIFEST.XML

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="ANDROID.PERMISSION.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2de.permission.RECEIVE"/>

<permission android:protectionLevel="signature" android:name="com.example.ani.parseexample.ParseApp.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.example.ani.parseexample.ParseApp.permission.C2D_MESSAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name=".ParseApp">
    <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>
</application>

<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="com.example.ani.parseexample.ParseApp"/>
    </intent-filter>
</receiver>

</manifest>

LOGCAT

Service com.android.providers.media.MtpService has leaked IntentReceiver android.mtp.MtpDatabase$1@3b5d3c26 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Service com.android.providers.media.MtpService has leaked IntentReceiver android.mtp.MtpDatabase$1@3b5d3c26 that was originally registered here. Are you missing a call to unregisterReceiver()?
        at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1003)
        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:767)
        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1749)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1729)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1723)
        at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:488)
        at android.mtp.MtpDatabase.setServer(MtpDatabase.java:619)
        at android.mtp.MtpServer.<init>(MtpServer.java:33)
        at com.android.providers.media.MtpService.manageServiceLocked(MtpService.java:259)
        at com.android.providers.media.MtpService.onStartCommand(MtpService.java:219)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3072)
        at android.app.ActivityThread.access$2100(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:155)
        at android.app.ActivityThread.main(ActivityThread.java:5696)
        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:1028)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

如果logcat中缺少某些信息,請告訴我。 我正在使用手機來運行該應用程序,它會給出許多有關系統中其他正在運行的進程的錯誤消息。 我已經將Parse-1.9.2.jar文件夾變成了一個庫,如果有幫助的話。 我還在https://parse.com/apps/quickstart#parse_push/android/native/existing上嘗試過解析示例,但這也沒有用。 有人可以幫忙嗎?

真誠的

阿尼

首先。

<uses-permission android:name="com.google.android.c2de.permission.RECEIVE"/>

應該可能是:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

c2dm不是c2de

另外,在某些地方使用com.example.anish ,在其他地方則使用com.example.ani 您應確保與清單/檔中定義的軟件包一致。

在您的permissionuses-permission和廣播接收者中,您應該保持一致。 在您的情況下,您的設置應類似於:

<!-- lowercase these 2 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/
<!-- end lowercase -->
...
<permission android:protectionLevel="signature" android:name="com.example.anish.parseexample.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.example.anish.parseexample.permission.C2D_MESSAGE"/>
...
<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.example.ani.parseexample"/>
    </intent-filter>
</receiver>

我從未使用過parse.com,但是以上內容是基於我對google cloud消息傳遞設置的理解。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM