0
votes

I want to use Parse to push notification. When I test app on the Android emulator, I found some devices have deviceToken some devices do not. If there is no deviceToken then this device cannot receive notification. How can I solve that? Below is my code.

public class ShooksApplication extends Application {

public void onCreate() {
    super.onCreate();

    Parse.initialize(this, "***********", "*******************");
    ParseInstallation installation = ParseInstallation.getCurrentInstallation();

    installation.saveInBackground();
}
}

And manifest is working because devices with deviceToken can receive notification. But I see the the pushType of all the data in Installation is gcm. Below is my manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cs442.project.team13" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<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.cs442.project.team13.permission.C2D_MESSAGE" />
<uses-permission android:name="com.cs442.project.team13.permission.C2D_MESSAGE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name=".ShooksApplication">
    <activity
        android:name="com.cs442.project.team13.MainPage"
        android:label="Search"
        android:theme="@style/Theme.MyCompatTheme">

        <meta-data
            android:name="android.app.default_searchable"
            android:value=".SearchBookResultsActivity" />
    </activity>

    <activity
        android:name="com.cs442.project.team13.SearchBookResultsActivity"
        android:label="SearchResult"
        android:theme="@style/Theme.MyCompatTheme">

        <!-- to identify this activity as "searchable" -->
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.app.default_searchable"
            android:value="com.example.ExampleActivity" />
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>

    <activity android:name="com.cs442.project.team13.WishListResult"
                android:label="Wishlist"/>
    <activity android:name="com.cs442.project.team13.Details"
        android:label="Details"/>








    <activity
        android:name="com.cs442.project.team13.LoginActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.cs442.project.team13.UpdateProfile" />

    <activity android:name="com.cs442.project.team13.RegisterActivity" />
    <activity
        android:name="com.cs442.project.team13.BookCategoryActivity"
        android:label="@string/title_activity_book_category" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.PostBookActivity"
        android:label="@string/title_activity_post_book" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.DisplayBookInfoActivity"
        android:label="@string/title_activity_display_book_info" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.DisplayProviderInfoActivity"
        android:label="@string/title_activity_display_provider_info" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.DisplayUserBookListActivity"
        android:label="@string/title_activity_display_user_book_list" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.UpdateBookInfoActivity"
        android:label="@string/title_activity_update_book_info" >
    </activity>
    <activity
        android:name="com.cs442.project.team13.CategorySearch"
        android:label="@string/title_activity_category_search" >
    </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" />
            <category android:name="com.cs442.project.team13" />
        </intent-filter>
    </receiver>

    <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/book126"/>
</application>

How can I solve this issue?

2
Have you setup everything into the manifest like receivers and service ? the installation should display gcm so that is not an issue. - Iulian
Hi, thank you for reply, yes, I set up receivers and service in my manifest, but issue is some devices installed with device token which can receive notification, but some cannot receive because of missing device token, I don't know why. - Chen
Can you edit your post and include the Manifest file? - Iulian
@IulianVărzaru hi, I edited my post, if there is something wrong, plz plz plz tell me, I really appreciate - Chen

2 Answers

0
votes

From what I can see in your Manifest the only solution might be removing

<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>
0
votes

Remember to add the following lines of code so that your .json file runs correctly

gradle:app

apply plugin: 'com.google.gms.google-services'

implementation 'com.google.firebase:firebase-core:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'

gradle:project

classpath 'com.google.gms:google-services:4.3.3'