Parse Push - how to automatically open an event without user action when receiving a push on Android

I have a requirement (android) where my application should automatically start its main action when receiving a push notification without clicking a button on the notification in the system tray. I have a map where it shows the current location, but in push, I get the location, and I need my map in the main action to move the camera to the current state when I receive a click and alert the user using custom sound. All this should happen without the user clicking anything. Help Pls. Thanks in advance.

+4
source share
2 answers

Yes it is possible. Parse.com documentation says:

You can also specify the intention to be launched in the background when a push notification is received. This will allow your application to perform custom processing for the notification and can be used regardless of whether you are selected to display the message in the system bar. To perform custom notification processing, set the Action entry to the push notification data dictionary into the action of the intent that you want to run. Android recommendations show that you prefix actions with your package name in order to avoid namespace conflicts with other application launches.

So, you send push notifications in this way:

JSONObject data = new JSONObject("{\"action\": \"com.example.UPDATE_STATUS\""}));

ParsePush push = new ParsePush();
push.setData(data);
push.sendPushInBackground();

AndroidManifest.xml , , push- com.example.UPDATE_STATUS:

<receiver android:name="com.example.MyBroadcastReceiver" android:exported="false">
  <intent-filter>
    <action android:name="com.example.UPDATE_STATUS" />
  </intent-filter>
</receiver>

:

public class MyBroadcastReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    context.startActivity(new Intent(context, MyActivity.class));
  }
}
+9

@makovkastar, V1.8. : com.example.UPDATE_STATUS.

push- : https://www.parse.com/tutorials/android-push-notifications

ParsePushBroadcastReceiver: https://gist.github.com/panchicore/97d5ad25842258576109 / : fooobar.com/questions/19218/...

, onPushReceive , push-, LocalBroadcastManager - , , .

+1

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


All Articles