Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Clicks Tracking

Add click tracking to the activity creation method.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Click tracking
    if (getIntent().getExtras() != null) {
        Personaсlick.notificationClicked(getIntent().getExtras());
    }
}


How To Use

Example show notification with download icon:

new AsyncTask<String, Void, Bitmap>() {

	@Override
	protected Bitmap doInBackground(String... params) {
		try {
			InputStream in = new URL(params[0]).openStream();
			return BitmapFactory.decodeStream(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected void onPostExecute(Bitmap result) {
		super.onPostExecute(result);

		Intent intent = new Intent(getApplicationContext(), MainActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

		//REQUIRED! For tracking click notification
        intent.putExtra(PersonaClick.NOTIFICATION_TYPE, data.get("type"));
        intent.putExtra(PersonaClick.NOTIFICATION_ID, data.get("id"));

		PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);

		NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), getString(R.string.notification_channel_id))
				.setSmallIcon(R.mipmap.ic_launcher)
				.setLargeIcon(result)
				.setStyle(new NotificationCompat.BigTextStyle().bigText(data.get("body")))
				.setContentTitle(data.get("title"))
				.setContentText(data.get("body"))
				.setAutoCancel(true)
				.setContentIntent(pendingIntent);

		NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		if( notificationManager != null ) {
			notificationManager.notify(0, notificationBuilder.build());
		} else {
			Log.e(PersonaClick.TAG, "NotificationManager not allowed");
		}
	}
}.execute(data.get("icon"));


Token Send

Method Objective

The method allows manually sending an Android push notification token to the system.

The SDK sends a token to the system automatically. You can use this method if you need to send the token forcibly yourself.

Syntax and parameters

PersonaClick.setPushTokenNotification(android_token, callback);
NameTypeRequirementDescription
android_tokenstringrequired

Android push notification token

callbackfunctionoptionallyThe callback function to which the API response will be passed

Example of use

PersonaClick.setPushTokenNotification("93b033a394da31b3160b8e0a35b80b6c16eb99a22ed34e88afe2a117dd4bc601", new Api.OnApiCallbackListener() {
	@Override
	public void onSuccess(JSONObject msg) {
		// API response processing functionality
	}
});


Payloads

The Payloads structures are available under Push Payloads (Mobile SDKs).

  • No labels