想要使用 android 台设备的解析向用户发送用户通知

want to send User to User notification using parse for android devices

我试图通过点击按钮向特定用户发送用户到用户的通知,但是在 android 的最后 4 天发送通知时遇到了这个问题,并且每当我从我用作模拟器的 phone,并重新安装它进行调试,它不会创建新的安装 ID 并采用旧的:我猜这是问题所在,如果有人帮助我,那将是很大的帮助阐述方式

这是我的自定义接收器代码:

public class CustomPushReceiver extends ParsePushBroadcastReceiver {
    private final String TAG = CustomPushReceiver.class.getSimpleName();

    private NotificationUtils notificationUtils;

    private Intent parseIntent;

    public CustomPushReceiver() {
        super();
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        super.onPushReceive(context, intent);

        if (intent == null)
            return;

        try {
            JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

            Log.e(TAG, "Push received: " + json);

            parseIntent = intent;

            parsePushJson(context, json);

        } catch (JSONException e) {
            Log.e(TAG, "Push message json exception: " + e.getMessage());
        }
    }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushOpen(Context context, Intent intent) {
        super.onPushOpen(context, intent);
    }

    /**
     * Parses the push notification json
     *
     * @param context
     * @param json
     */
    private void parsePushJson(Context context, JSONObject json) {
        try {
            boolean isBackground = json.getBoolean("is_background");
            JSONObject data = json.getJSONObject("data");
            String title = data.getString("title");
            String message = data.getString("message");

            if (!isBackground) {
                Intent resultIntent = new Intent(context, MainActivity.class);
                showNotificationMessage(context, title, message, resultIntent);
            }

        } catch (JSONException e) {
            Log.e(TAG, "Push message json exception: " + e.getMessage());
        }
    }


    /**
     * Shows the notification message in the notification bar
     * If the app is in background, launches the app
     *
     * @param context
     * @param title
     * @param message
     * @param intent
     */
    private void showNotificationMessage(Context context, String title, String message, Intent intent) {

        notificationUtils = new NotificationUtils(context);

        intent.putExtras(parseIntent.getExtras());

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

        notificationUtils.showNotificationMessage(title, message, intent);
    }
}

和我的 ParseQuery:

try {
                    ParseQuery userQuery = new ParseQuery(ParseUser.class);
                    userQuery.whereNear("Location",
                            currentUser.getParseGeoPoint("Location"));
                    userQuery.setLimit(10);
                    userQuery.whereEqualTo("Type", "Doctor");
                    userQuery.whereEqualTo("deviceType", "android");
                    userQuery.findInBackground();
                    // Find devices associated with these users
                    ParseQuery pushQuery = ParseInstallation.getQuery();
                    pushQuery.whereMatchesQuery("user", userQuery);
                    // Send push notification to query
                    ParsePush push = new ParsePush();
                    push.setQuery(pushQuery);
                    push.setMessage("Only users near"
                            + currentUser.getParseGeoPoint("Location")
                            + " will recieve this push notification");
                    push.sendInBackground(new SendCallback() {

                        @Override
                        public void done(ParseException e) {
                            if (e == null) {
                                Toast.makeText(getApplicationContext(),
                                        "Notification Sent", Toast.LENGTH_LONG)
                                        .show();
                            } else {
                                Toast.makeText(getApplicationContext(),
                                        "Notification not Sent",
                                        Toast.LENGTH_LONG).show();
                            }
                        }

                    });

                } catch (Exception e) {
                    e.printStackTrace();
                }

我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aspire.wecare"
    android:versionCode="1"
    android:versionName="1.0" >

    <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.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="com.aspire.wecare.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.aspire.wecare.permission.C2D_MESSAGE" />

    <permission
        android:name="com.aspire.wecare.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.aspire.wecare.permission.MAPS_RECEIVE" />

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

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



        <activity
            android:name="com.aspire.wecare.Welcome"
            android:label="@string/title_activity_welcome" >
        </activity>
        <activity
            android:name="com.aspire.wecare.LoginActivity"
            android:label="@string/title_login" >
        </activity>
        <activity
            android:name="com.aspire.wecare.LoginSignupActivity"
            android:label="@string/title_activity_login_signup" >
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyBA3_YfEl2cnZ8uDmrI23g8W7l1y2Xiku8" />
      <!-- Added for Parse push notifications -->

        <service android:name="com.parse.PushService" />

        <receiver
            android:name=".receiver.CustomPushReceiver"
            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" />
            </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.aspire.wecare" />
            </intent-filter>
        </receiver>

        <!-- /Added for Parse push notifications -->
    </application>

</manifest>

一般来说,

(1) 您将在 云代码 中执行此操作。幸运的是,一旦开始就非常容易。事实上,这是一个类似问题的完整解释。

更重要的是,

(2) 请注意,您使用的工具错误。 您没有使用 'Push' 来实现您想要实现的目标。 您应该使用 PubNub、Firebase、Pusher 或类似的服务.将其中之一 与 Parse.

结合使用是司空见惯的事