Parse Push JSON data output on Android

I am new to Android and I really hope that this will be easy to solve for you guys!

I would like to allow users to send push to other users after clicking a button in my application. It configured ParsePush correctly on my button click listener because it works fine:

            // Create our Installation query
            ParseQuery pushQuery = ParseInstallation.getQuery();
            pushQuery.whereEqualTo("installationId", installationId); //Send to targeted user

            // Send push notification to query
            ParsePush push = new ParsePush();
            push.setQuery(pushQuery); // Set our Installation query

            push.setMessage("HEY YOU");
            push.sendInBackground();

But I would like to add a URI to my push, so I did:

                // Create our Installation query
            ParseQuery pushQuery = ParseInstallation.getQuery();
            pushQuery.whereEqualTo("installationId", installationId);

            // Send push notification to query
            ParsePush push = new ParsePush();
            push.setQuery(pushQuery); // Set our Installation query

            String string = "{\"title\" : \"my title\",\"alert\" : \"my alert text\",\"uri\" : \"myapp://host/path\"}";

            try {
                JSONObject data = new JSONObject(string);
                push.setData(data);
            } catch (JSONException e) {
                Log.e("MYAPP", "unexpected JSON exception", e);
            }

            push.sendInBackground();

In my Android manifest, I have target activity:

        <activity android:name=".Accept_Action">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="myapp" android:host="host" android:path="/path" />
        </intent-filter>
    </activity>

But for some reason this does not work. The push never lands on my target device. Can you help me do this job? Thanks

+4
source share
1 answer

Answer your question

, "uri" .

:

:

sendInBackground(), , :

push.sendInBackground(new SendCallback() {
            @Override
            public void done(ParseException e) {
                if (e != null) {
                    e.printStackTrace();
                } else {
                    Log.e("MYAPP", "Push sent.");
                }
            }
        });

, e.printStackTrace(); 115:

com.parse.ParseRequest$ParseRequestException: Client-initiated push cannot use the "uri" option
+1

Source: https://habr.com/ru/post/1627371/


All Articles