Make sure you've integrated Pushwoosh SDK into your Android project:
In order to track in-app purchases, you should call the sendInappPurchase
method of the Pushwoosh
class when a user buys a product:
public void sendInappPurchase(java.lang.String sku,java.math.BigDecimal price,java.lang.String currency)
sku
– purchased product ID
price
– price of the product
currency
– currency of the price (ex: “USD”)
ExamplePushwoosh.getInstance().sendInappPurchase("com.example.inapp1", new BigDecimal(1.99), "USD");
In your activity that will handle the deep link, add <data> tag with the scheme, host, and pathPrefix parameters.
<activityandroid:name=".PromoActivity"android:label="PromoActivity"><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="com.pushwoosh"android:host="promotion"android:pathPrefix="" /></intent-filter></activity>
Deep link page name (promotion in the example given) goes to the host field, not pathPrefix.
In the example above, the deep link will open PromoActivity. The basic implementation below displays alert with promo id value for the sake of simplicity. In your application it could definitely do something useful!
public class PromoActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.deep_link);setTitle("Deep link activity");Intent intent = getIntent();String action = intent.getAction();Uri data = intent.getData();if (TextUtils.equals(action, Intent.ACTION_VIEW)){openUrl(data);}}private void openUrl(Uri uri){String promoId = uri.getQueryParameter("id");Toast.makeText(getApplicationContext(), promoId, Toast.LENGTH_LONG).show();}}
To use geozone pushes, simply add com.pushwoosh:pushwoosh-location
library and call
PushwooshLocation.startLocationTracking();
It is recommended to check dynamic permissions android.Manifest.permission.ACCESS_FINE_LOCATION
and android.Manifest.permission.ACCESS_COARSE_LOCATION
before invoking this method.
If you use Pushwoosh Local Notifications API, add RECEIVE_BOOT_COMPLETED permission to your AndroidManifest.xml:
AndroidManifest.xml<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>x
Pushwoosh supports setting badge number on the app icon shortcut for the following Android launchers:
Sony, Samsung, LG, HTC, Xiaomi, ASUS, ADW, APEX, NOVA, HUAWEI, ZUK, OPPO.
To use this functionality, simply add com.pushwoosh:pushwoosh-badge
library to your application.
If you want to start a particular activity in response to push notifications, add the following intent-filter to that activity:
AndroidManifest.xml<activity android:name="YourActivity"><intent-filter><meta-data android:name="com.pushwoosh.log_level" android:value="ERROR" /><action android:name="${applicationId}.MESSAGE"/><category android:name="android.intent.category.DEFAULT"/></intent-filter></activity>
In order to assist with debugging and integration, SDK will print all the requests to the console by default. When you are ready for the production build, add com.pushwoosh.log_level
meta-data with value "ERROR" to the AndroidManifest.xml. This way only information about errors will go to the console. Other option could be one of the following:
NONE - No logs from the SDK ERROR - Display only errors in the console WARN - Display also a warnings INFO - Display informational messages DEBUG - Even debug information is displayed now NOISE - Everything SDK can print and more
AndroidManifest.xml<meta-data android:name="com.pushwoosh.log_level" android:value="ERROR" />
When using Proguard, add the following options:
proguard-rules.pro-keep class com.pushwoosh.** { *; }-dontwarn com.pushwoosh.**
See Google Play Services library requirements regarding Proguard here: https://developers.google.com/android/guides/setup
If you need to programmatically select which activity to display as a result of push notification, you can create custom NotificationServiceExtension and include fully qualified class name of your NotificationServiceExtension in metadata under com.pushwoosh.notification_service_extension
value.
AndroidManifest.xml<meta-dataandroid:name="com.pushwoosh.notification_service_extension"android:value="com.your.package.YourNotificationServiceExtension" / >
YourNotificationServiceExtension.javapublic class YourNotificationServiceExtension extends NotificationServiceExtension {@Overrideprotected void startActivityForPushMessage(PushMessage message) {// super.startActivityForPushMessage() starts default launcher activity// or activity marked with ${applicationId}.MESSAGE action.// Simply do not call it to override this behaviour.// super.startActivityForPushMessage(message);// start your activity instead:Intent launchIntent = new Intent(getApplicationContext(), YourActivity.class);launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// (Optional) pass notification data to ActivitylaunchIntent.putExtra(Pushwoosh.PUSH_RECEIVE_EVENT, message.toJson().toString());context.startActivity(launchIntent);}}
Important
If you use proguard in production builds, make sure your custom NotificationServiceExtension is not obfuscated ( by adding -keep class
rule), otherwise it will lead to ClassNotFoundException.
To customize the view of push notifications, you need to create a custom Factory, you can create custom NotificationFactory and include fully qualified class name of your NotificationFactory in metadata under com.pushwoosh.notification_factory
value.
AndroidManifest.xml<meta-dataandroid:name="com.pushwoosh.notification_factory"android:value="com.your.package.YourNotificationFactory" / >
YourNotificationFactorypublic class YourNotificationFactory extends PushwooshNotificationFactory {@Overridepublic Notification onGenerateNotification(@NonNull PushMessage pushMessage) {if (customNotification) {// TODO: generate and return custom notification}// return default Pushwoosh notificationreturn super.onGenerateNotification(pushMessage);}}
To customize the appearance of a group summary, create a custom Factory. You can create custom SummaryNotificationFactory and include fully qualified class name of your SummaryNotificationFactory in metadata under com.pushwoosh.summary_notification_factory value.
AndroidManifest.xml<meta-dataandroid:name="com.pushwoosh.summary_notification_factory"android:value="com.your.package.YourSummaryNotificationFactory" />
YourSummaryNotificationFactorypublic class YourSummaryNotificationFactory extends PushwooshSummaryNotificationFactory {@Overridepublic String summaryNotificationMessage(int notificationsAmount) {// return the message you wantreturn super.summaryNotificationMessage(notificationsAmount);}@Overridepublic int summaryNotificationIconResId() {// return the icon resource id you wantreturn super.summaryNotificationIconResId();}}
For Private Offering subscriptions only.
Pushwoosh provides Private endpoints for customers with Private Offering subscriptions. To set up Private endpoint for Android SDK, you need to add the following to your AndroidManifest.xml file:
AndroidManifest.xml<meta-data android:name="com.pushwoosh.base_url" android:value="PUSHWOOSH_PRIVATE_ENDPOINT_URL_PROVIDED" />
In case there are several Rich Media pages to display simultaneously (for example, trigger events for two or more In-Apps take place at one moment, or a Rich Media page is being displayed already at the moment a different trigger event occurs), you can set up a queue for Rich Media pages displaying. To create a queue, add the following code to your project:
Application.javapackage com.pushwoosh.testingapp;import com.pushwoosh.RichMediaManager;import com.pushwoosh.exception.PushwooshException;import com.pushwoosh.richmedia.RichMediaPresentingDelegate;import com.pushwoosh.richmedia.RichMedia;import com.pushwoosh.internal.utils.PWLog;import java.util.ArrayDeque;import java.util.concurrent.locks.ReentrantLock;public class DefaultRichMediaPresentingDelegate implements RichMediaPresentingDelegate {private final String TAG = DefaultRichMediaPresentingDelegate.class.getSimpleName();private ArrayDeque<RichMedia> richMediaQueue = new ArrayDeque<>();private RichMedia currentRichMedia = null;private ReentrantLock reentrantLock;public DefaultRichMediaPresentingDelegate() {PWLog.noise(TAG, "new DefaultRichMediaPresentingDelegate:" + this);reentrantLock = new ReentrantLock();}@Overridepublic boolean shouldPresent(RichMedia richMedia) {PWLog.noise(TAG, "shouldPresent:" + richMedia);if (currentRichMedia == null) {PWLog.noise(TAG, "currentRichMedia is null");}if (richMedia.isLockScreen()) {PWLog.noise(TAG, "isLockScreen is true");return true;}try {reentrantLock.lock();if (currentRichMedia == null) {PWLog.noise(TAG, "show:" + richMedia);currentRichMedia = richMedia;return true;} else {PWLog.noise(TAG, "add to queue:" + richMedia);richMediaQueue.add(richMedia);return false;}} finally {reentrantLock.unlock();}}@Overridepublic void onPresent(RichMedia richMedia) {PWLog.noise(TAG, "onPresent" + richMedia);}@Overridepublic void onError(RichMedia richMedia, PushwooshException pushwooshException) {PWLog.error(TAG, pushwooshException + " richMedia:"+richMedia.toString());tryShowNextRichMediaThreadSafety();}@Overridepublic void onClose(RichMedia richMedia) {PWLog.noise(TAG, "onClose:" + richMedia);tryShowNextRichMediaThreadSafety();}private void tryShowNextRichMediaThreadSafety() {try {reentrantLock.lock();tryShowNextRichMedia();} finally {reentrantLock.unlock();}}private void tryShowNextRichMedia() {if (!richMediaQueue.isEmpty()) {currentRichMedia = richMediaQueue.poll();PWLog.noise(TAG, "try manual show:" + currentRichMedia);RichMediaManager.present(currentRichMedia);} else {PWLog.noise(TAG, "richMediaQueue is empty");currentRichMedia = null;}}}
We strongly recommend to set up a queue in Application instead of Activity. Otherwise, it may create several queues.
Available for Android 8+ devices.
Put your audio file in the proper folder. For the native Android framework, your files should be placed in the /app/src/main/res/raw
folder.
Please refer to the corresponding guides to find where to place the audio file in projects built in other frameworks.
2. Create a Notification Channel.
3. Select a sound while configuring a push message.
4. Set the Notification Channel the message will belong to. To do so, specify the following in the “Android root params” field:{"pw_channel": "PUSH NOTIFICATION CHANNEL NAME"} //
here you need to specify the name for your channel with custom sound
In case of using remote API, set the parameters as follows within your /createMessage API request:
"android_root_params": {"pw_channel": "push"} // here you need to specify the name for your channel with custom sound, for example, "push" for the notifications with push.wav sound."android_sound": "push" // here you should specify the file name without extension
Once you send the push with those params specified, the Notification Channel with the selected sound is created for all devices with Android 8+.
Now, to send the push with a custom sound, you have to specify only the channel associated with that sound.