ข้ามไปยังเนื้อหา

การปรับแต่ง Xamarin Android

การติดตามการซื้อภายในแอป

Anchor link to

เพื่อติดตามการซื้อภายในแอป คุณควรเรียกใช้เมธอด SendInappPurchase ของคลาส PushNotificationsManager เมื่อผู้ใช้ซื้อสินค้า:

public virtual void SendInappPurchase (string sku, BigDecimal price, string currency);
  • sku – ID ของสินค้าที่ซื้อ
  • price – ราคาของสินค้า
  • currency – สกุลเงิน (เช่น: “USD”)

ตัวอย่าง:

PushNotificationsManager.Instance.SendInappPurchase("com.your.app.Marketing", BigDecimal.ValueOf(149.95), "USD");
Anchor link to

เพิ่มแอตทริบิวต์ IntentFilter ไปยังคลาส activity ของคุณที่จะจัดการกับ deep link ดังนี้:

using Android.Content;
using Android.Content.PM;
[Activity(Label = "PromoActivity",
ConfigurationChanges = ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "com.pushwoosh",
DataHost = "promotion")]
class PromoActivity : Activity

ในตัวอย่างข้างต้น deep link จะเปิด PromoActivity การใช้งานพื้นฐานด้านล่างจะแสดงการแจ้งเตือนพร้อมค่า promo id เพื่อความเรียบง่าย

using System;
using Android.App;
using Android.OS;
using Android.Text;
using Android.Widget;
using Android.Content;
using Android.Content.PM;
namespace PushwooshSample
{
[Activity(Label = "PromoActivity",
ConfigurationChanges = ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "com.pushwoosh",
DataHost = "promotion")]
public class PromoActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Title = "Deep link activity";
Intent intent = Intent;
String action = intent.Action;
var data = intent.Data;
if (TextUtils.Equals(action, Intent.ActionView))
{
OpenUrl(data);
}
}
void OpenUrl(Android.Net.Uri uri)
{
String promoId = uri.GetQueryParameter("id");
Toast.MakeText(ApplicationContext, promoId, ToastLength.Long).Show();
}
}
}

การใช้ Badges บน Android

Anchor link to

Pushwoosh รองรับการตั้งค่าหมายเลข badge บนทางลัดไอคอนแอปสำหรับ Android launchers ต่อไปนี้:
Sony, Samsung, LG, HTC, ASUS, ADW, APEX, NOVA, HUAWEI, ZUK, OPPO

ตัวอย่าง:

using Pushwoosh.Badge;
PushwooshBadge.BadgeNumber = badgeInt;

การเปิด Activity แบบกำหนดเอง

Anchor link to

หากคุณต้องการเริ่ม activity ที่ต้องการเพื่อตอบสนองต่อการแจ้งเตือนแบบพุช ให้เพิ่ม IntentFilter ต่อไปนี้ไปยัง activity นั้น:

[Activity]
[IntentFilter(new[] { "${applicationId}.MESSAGE" }, Categories = new[] { Intent.CategoryDefault })]
public class MyActivity : Activity

การควบคุมระดับ Log

Anchor link to

เพื่อช่วยในการดีบักและการผสานรวม โดยค่าเริ่มต้น SDK จะพิมพ์คำขอทั้งหมดไปยังคอนโซล เมื่อคุณพร้อมสำหรับเวอร์ชันโปรดักชัน ให้เพิ่ม meta-data “PW_LOG_LEVEL” ที่มีค่า “ERROR” ไปยัง AndroidManifest.xml วิธีนี้จะทำให้มีเพียงข้อมูลเกี่ยวกับข้อผิดพลาดเท่านั้นที่จะไปยังคอนโซล ตัวเลือกอื่นๆ อาจเป็นหนึ่งในรายการต่อไปนี้:

NONE - ไม่มี log จาก SDK
ERROR - แสดงเฉพาะข้อผิดพลาดในคอนโซล
WARN - แสดงคำเตือนและข้อผิดพลาด
INFO - แสดงข้อความข้อมูล
DEBUG - แม้กระทั่งข้อมูลดีบักก็จะถูกแสดง
NOISE - ทุกสิ่งที่ SDK สามารถพิมพ์ได้

<meta-data android:name="com.pushwoosh.log_level" android:value="ERROR" />

การใช้ ProGuard

Anchor link to

เพิ่มตัวเลือกต่อไปนี้หากคุณใช้ ProGuard:

-keep class com.pushwoosh.** { *; }
-dontwarn com.pushwoosh.**

การปรับแต่งพฤติกรรมการเปิดการแจ้งเตือน

Anchor link to

หากคุณต้องการเลือกว่าจะแสดง activity ใดอันเป็นผลมาจากการแจ้งเตือนแบบพุช คุณสามารถสร้าง NotificationServiceExtension แบบกำหนดเอง และระบุชื่อคลาสแบบเต็มของ NotificationServiceExtension ของคุณใน metadata ภายใต้ค่า “com.pushwoosh.notification_service_extension”

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Pushwoosh.Notification;
[assembly: MetaData("com.pushwoosh.notification_service_extension",
Value = "com.your.package.YourNotificationServiceExtension")]
namespace YourNamespace
{
[Register("com/your/package/YourNotificationServiceExtension")]
public class YourNotificationServiceExtension : NotificationServiceExtension
{
protected override void StartActivityForPushMessage(PushMessage message)
{
// base.StartActivityForPushMessage(message) starts default launcher activity
// or activity marked with ${applicationId}.MESSAGE action.
// Simply do not call it to override this behaviour.
// start your activity instead:
Intent launchIntent = new Intent(ApplicationContext, typeof(YourActivity));
launchIntent.SetFlags(ActivityFlags.NewTask);
ApplicationContext.StartActivity(launchIntent);
}
}
}

การปรับแต่งการแจ้งเตือนแบบพุช

Anchor link to

ในการปรับแต่งมุมมองของการแจ้งเตือนแบบพุช คุณต้องสร้าง Factory แบบกำหนดเอง คุณสามารถสร้าง NotificationFactory แบบกำหนดเอง และระบุชื่อคลาสแบบเต็มของ NotificationFactory ของคุณใน metadata ภายใต้ค่า “com.pushwoosh.notification_factory”

<meta-data
android:name="com.pushwoosh.notification_factory"
android:value="com.your.package.YourNotificationFactory" />
using System;
using Android.App;
using Android.Runtime;
using Pushwoosh.Notification;
[assembly: MetaData("com.pushwoosh.notification_factory",
Value = "com.your.package.YourAppNotificationFactory")]
namespace PushwooshSample
{
[Register("com/your/package/YourAppNotificationFactory")]
public class YourAppNotificationFactory : PushwooshNotificationFactory
{
public override Notification OnGenerateNotification(PushMessage pushData)
{
// TODO: generate and return custom notification
return base.OnGenerateNotification(pushData);
}
}
}

URL ของ Private Endpoint

Anchor link to

Pushwoosh มี Private endpoint ให้สำหรับลูกค้าที่สมัครสมาชิก Custom Plan ในการตั้งค่า Private endpoint สำหรับ SDK คุณต้องเพิ่มข้อมูลต่อไปนี้ลงในไฟล์ AndroidManifest.xml ของคุณ:

<meta-data android:name="com.pushwoosh.base_url" android:value="PUSHWOOSH_PRIVATE_ENDPOINT_URL_PROVIDED" />

แบ่งปันความคิดเห็นของคุณกับเรา

Anchor link to

ความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น เราจึงยินดีที่จะรับฟังจากคุณหากคุณมีปัญหาใดๆ ในระหว่างขั้นตอนการผสานรวม SDK หากคุณประสบปัญหาใดๆ โปรดอย่าลังเลที่จะแบ่งปันความคิดของคุณกับเรา ผ่านแบบฟอร์มนี้