SDK

Implementation

In this page let's dive deeper into how passes are handled in your Android app. In order for our library to be able to open passes distribute via a push notification, a link in an email or in a website you need to declare an activity like the one below in your AndroidManifest.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<activity
	android:name="re.notifica.ui.PassbookActivity"
	android:configChanges="keyboardHidden|orientation|screenSize"
	android:hardwareAccelerated="true">
	<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:host="push.notifica.re"
			android:pathPrefix="/pass/forapplication/{NOTIFICARE_APP_ID}"
			android:scheme="https" />
	</intent-filter>
</activity>

Make sure you replace the {NOTIFICARE_APP_ID} with your app's actual ID. You can find it in our dashboard as described here. Adding this entry to your Android Manifest is all it takes to start handling digital cards.

There are also a couple of launch options for passes. This should be done at launch in our Application. If you wish that a pass is constantly shown in the lock screen (even if the user dismisses it) while it is relevant, you should set the following option to true:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class MyBaseApplication extends Application {
	@Override
	public void onCreate() {
		super.onCreate();


		//Launch Notificare system
		Notificare.shared().launch(this);

		...more code

		Notificare.shared().setPassbookRelevanceOngoing(true);


		...more code
	}
}

You can also provide a default relevant text, which will be shown whenever a pass is relevant and a value for this field has not been included in the pass. To do that you can provide the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class MyBaseApplication extends Application {
	@Override
	public void onCreate() {
		super.onCreate();


		//Launch Notificare system
		Notificare.shared().launch(this);

		...more code

		Notificare.shared().setRelevanceText("This pass is now relevant because %s");

		...more code
	}
}

Finally, you can also override the passes' Icon which is also included in the pass and provide yourself a different resource. This icon will be shown in the lock screen whenever the pass is relevant or its values have changed. To do this, simply invoke the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class MyBaseApplication extends Application {
	@Override
	public void onCreate() {
		super.onCreate();


		//Launch Notificare system
		Notificare.shared().launch(this);

		...more code

		Notificare.shared().setRelevanceIcon(R.drawable.notificare_passbook_style);

		...more code
	}
}

You can also at any point in your application, retrieve the list of passes stored in your application. To do that you simply need to invoke the following method:

1
2
3
4
5
6
Notificare.shared().getPassbookManager().getPasses();

//You can iterate over passes like this
for (Passbook pass : Notificare.shared().getPassbookManager().getPasses()) {
	System.out.println(pass.getSerialNumber());
}

In most cases you will only need to use our default UI to handle passes. But there might be situations, where you might want to obtain a pass object to let's say retrieve its contents. If you know the passes' serial number you can use the method below to retrieve a serialized model:

1
2
3
4
5
6
7
8
9
10
11
12
13
...more code

Notificare.shared().getPassbookManager().fetchPass("SERIAL_NUMBER", new NotificareCallback<NotificarePass>() {
	@Override
	public void onSuccess(NotificarePass notificarePass) {

	}

	@Override
	public void onError(NotificareError notificareError) {

	}
});