# SDK Methods

## Manually Triggering the Permission Dialog

You may choose to disable automatic triggering of the permission dialog via the platform. In this scenario you would choose to trigger the dialog based on your own criteria (eg: after a visitor interacts with a modal / soft prompt, visits a specific screen/page, etc).

The following code will manually trigger the dialog:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.PushNotifications.showPermissionPrompt(completion = { granted, response, error ->
    // Optional callback
    println("User accepted permissions: $granted")
}
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.PushNotifications.showPermissionPrompt((granted, response, error) -> {
    // Optional callback
    System.out.printf("User accepted permissions: %b", granted);
    return null;
});
```

{% endtab %}
{% endtabs %}

## Adding Attributes to a Subscriber's Profile

You can add attributes to a subscriber's profile and later perform segmentation based on those attributes. For example, you may want to tag visitors who are interested in a specific type of news (eg: politics, sports) so that you can target them with specific notifications.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.UserProfile.set(key="interests", value=listOf("politics", "news"))
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.UserProfile.set("interests", List.of("politics", "news"));
```

{% endtab %}
{% endtabs %}

If you want to set more than one attribute at a time you can also send a map of values. The following example sets both a `is_paying_subscriber` and `interests` attribute on the subscriber.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.UserProfile.set(data=hashMapOf(
  "is_paying_subscriber" to true,
  "interests" to listOf("politics", "news")
))
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.UserProfile.set(Map.of(
  "is_paying_subscriber", true,
  "interests", List.of("politics", "news")
));
```

{% endtab %}
{% endtabs %}

If you're storing the value of a property as an array you can use the `append` and `remove` methods to add or remove values:

{% tabs %}
{% tab title="Kotlin" %}

```swift
// add 'sports' to the subscriber's existing interests
PushSDK.UserProfile.append(key = "interests", values = listOf("sports"))

// remove 'fashion' and 'news' from the subscriber's interests
PushSDK.UserProfile.remove(key = "interests", values = listOf("fashion", "news"))
```

{% endtab %}

{% tab title="Java" %}

```java
// add 'sports' to the subscriber's existing interests
PushSDK.UserProfile.append("interests", List.of("sports"));

// remove 'fashion' and 'news' from the subscriber's interests
PushSDK.UserProfile.remove("interests", List.of("fashion", "news"));
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Properties using the `append` and `remove` methods will only store the most recent 20 values provided.
{% endhint %}

## Activity Tracking (URL / Screen Visits)

To track the subscriber flow through your application you can use activity tracking. You can track via screen or URL and pass associated metadata/tags if desired.

This information can then be used in segmentation to create cohorts of subscribers that have visited specific URLs or screens with tags based on number of visits and recency. For example: "Subscribers who have visited a page/screen tagged with "Astrology" at least 4 times in the last 30 days".

{% tabs %}
{% tab title="Kotlin" %}
To track a URL or screen visited along with the keyword/tag metadata:

```kotlin
PushSDK.UserProfile.trackActivity(name="myapp://dashboard", tags=listOf("my-tag"))
```

Or if there are no tags to be provided omit the `tags` parameter:

```kotlin
PushSDK.UserProfile.trackActivity(name="https://www.pushly.com/article-1")
```

{% endtab %}

{% tab title="Java" %}
To track a URL or screen visited along with the keyword/tag metadata:

```java
PushSDK.UserProfile.trackActivity("myapp://dashboard", List.of("my-tag"));
```

Or if there are no tags to be provided omit the `2nd` parameter:

```java
PushSDK.UserProfile.trackActivity("https://pushly.com/article-1");
```

{% endtab %}
{% endtabs %}

## Retrieving Your Anonymous Push ID

The PushSDK automatically assigns an anonymous Push ID for event tracking and debugging purposes.

Run the following code to return the Push ID:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val pushId = PushSDK.UserProfile.anonymousId
```

{% endtab %}

{% tab title="Java" %}

```java
String pushId = PushSDK.UserProfile.getAnonymousId();
```

{% endtab %}
{% endtabs %}

## Setting the Subscriber's External ID

Providing a unique User ID for your subscriber allows you to later interact with that subscriber via the API.

Once a subscriber's external ID has been set you may work with our team to set up bi-directional automated data syncs. The following use cases are common ways that publishers use the external ID via server-to-server requests:

* Sending notifications to individual subscribers programmatically
* Processing unsubscribe requests
* Adding and removing profile attributes and events to subscribers

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.UserProfile.externalId = "external-id"
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.UserProfile.setExternalId("external-id");
```

{% endtab %}
{% endtabs %}

You can also check to see if the subscriber is already tagged with an External ID:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val currentExternalId = PushSDK.UserProfile.externalId
```

{% endtab %}

{% tab title="Java" %}

```java
String currentExternalId = PushSDK.UserProfile.getExternalId();
```

{% endtab %}
{% endtabs %}

## Determining if a Visitor is Already Subscribed

If you need to know if a user is already subscribed to notifications the following snippet can be used:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val subscribed = PushSDK.PushNotifications.isSubscribed
```

{% endtab %}

{% tab title="Java" %}

```java
Boolean subscribed = PushSDK.PushNotifications.isSubscribed();
```

{% endtab %}
{% endtabs %}

## Determining if a Visitor is Eligible to Prompt

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val isEligible = PushSDK.PushNotifications.isEligibleToPrompt
```

{% endtab %}

{% tab title="Java" %}

```java
Boolean isEligible = PushSDK.PushNotifications.isEligibleToPrompt();
```

{% endtab %}
{% endtabs %}

## Pausing / Resuming a User's Notifications (Soft Unsubscribe)

A user's notifications can be paused by calling the following method:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.PushNotifications.pause()
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.PushNotifications.pause();
```

{% endtab %}
{% endtabs %}

If the user's notifications should be resumed call the following method:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.PushNotifications.resume()
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.PushNotifications.resume();
```

{% endtab %}
{% endtabs %}

To check if the user's notifications are currently paused:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val isPaused = PushSDK.PushNotifications.isPaused
```

{% endtab %}

{% tab title="Java" %}

```java
Boolean isPaused = PushSDK.PushNotifications.isPaused();
```

{% endtab %}
{% endtabs %}

## Permanently Delete a User

If the user should be excluded from all notifications and tracking run the following method:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.UserProfile.requestUserDeletion()
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.UserProfile.requestUserDeletion();
```

{% endtab %}
{% endtabs %}

## Setting the SDK Log Level

The PushSDK log level is set to `NONE` by default. Supported log levels are: `VERBOSE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, and `NONE`.

To enable more detailed logging add the following code in your application's main `onCreate` method:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
PushSDK.logLevel = PNLogLevel.INFO
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.setLogLevel(PNLogLevel.INFO);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.pushly.com/integration/implementation-steps/android/sdk-kotlin-java/sdk-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
