public final class

ShareData

extends java.lang.Object

 java.lang.Object

↳androidx.browser.trusted.sharing.ShareData

Gradle dependencies

compile group: 'androidx.browser', name: 'browser', version: '1.8.0'

  • groupId: androidx.browser
  • artifactId: browser
  • version: 1.8.0

Artifact androidx.browser:browser:1.8.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.browser:browser com.android.support:customtabs

Overview

Contains data to be delivered to a Web Share Target via a Trusted Web Activity. See TrustedWebActivityIntentBuilder.setShareParams(ShareTarget, ShareData).

Summary

Fields
public static final java.lang.StringKEY_TEXT

Bundle key for ShareData.text.

public static final java.lang.StringKEY_TITLE

Bundle key for ShareData.title.

public static final java.lang.StringKEY_URIS

Bundle key for ShareData.uris.

public final java.lang.Stringtext

Text of the shared message.

public final java.lang.Stringtitle

Title of the shared message.

public final java.util.List<Uri>uris

URIs of files to be shared.

Constructors
publicShareData(java.lang.String title, java.lang.String text, java.util.List<Uri> uris)

Creates a ShareData with the given parameters.

Methods
public static ShareDatafromBundle(Bundle bundle)

Unpacks the object from a .

public BundletoBundle()

Packs the object into a

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final java.lang.String KEY_TITLE

Bundle key for ShareData.title.

public static final java.lang.String KEY_TEXT

Bundle key for ShareData.text.

public static final java.lang.String KEY_URIS

Bundle key for ShareData.uris.

public final java.lang.String title

Title of the shared message.

public final java.lang.String text

Text of the shared message.

public final java.util.List<Uri> uris

URIs of files to be shared.

Constructors

public ShareData(java.lang.String title, java.lang.String text, java.util.List<Uri> uris)

Creates a ShareData with the given parameters.

Parameters:

title: The ShareData.title.
text: The ShareData.text.
uris: The ShareData.uris.

Methods

public Bundle toBundle()

Packs the object into a

public static ShareData fromBundle(Bundle bundle)

Unpacks the object from a .

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.browser.trusted.sharing;

import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * Contains data to be delivered to a Web Share Target via a Trusted Web Activity.
 * See {@link androidx.browser.trusted.TrustedWebActivityIntentBuilder#setShareParams}.
 */
public final class ShareData {
    /** Bundle key for {@link #title}. */
    public static final String KEY_TITLE = "androidx.browser.trusted.sharing.KEY_TITLE";

    /** Bundle key for {@link #text}. */
    public static final String KEY_TEXT = "androidx.browser.trusted.sharing.KEY_TEXT";

    /** Bundle key for {@link #uris}. */
    public static final String KEY_URIS = "androidx.browser.trusted.sharing.KEY_URIS";

    /** Title of the shared message. */
    @Nullable
    public final String title;

    /** Text of the shared message. */
    @Nullable
    public final String text;

    /** URIs of files to be shared. */
    @Nullable
    public final List<Uri> uris;

    /**
     * Creates a {@link ShareData} with the given parameters.
     * @param title The {@link #title}.
     * @param text The {@link #text}.
     * @param uris The {@link #uris}.
     */
    public ShareData(@Nullable String title, @Nullable String text, @Nullable List<Uri> uris) {
        this.title = title;
        this.text = text;
        this.uris = uris;
    }

    /** Packs the object into a {@link Bundle} */
    @NonNull
    public Bundle toBundle() {
        Bundle bundle = new Bundle();
        bundle.putString(KEY_TITLE, title);
        bundle.putString(KEY_TEXT, text);
        if (uris != null) {
            bundle.putParcelableArrayList(KEY_URIS, new ArrayList<>(uris));
        }
        return bundle;
    }

    /** Unpacks the object from a {@link Bundle}. */
    @NonNull
    @SuppressWarnings("deprecation")
    public static ShareData fromBundle(@NonNull Bundle bundle) {
        return new ShareData(bundle.getString(KEY_TITLE),
                bundle.getString(KEY_TEXT),
                bundle.getParcelableArrayList(KEY_URIS));
    }
}