|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.android.gms.snippets; |
| 16 | + |
| 17 | +import android.content.Context; |
| 18 | +import android.util.Log; |
| 19 | +import com.google.android.gms.ads.mediation.InitializationCompleteCallback; |
| 20 | +import com.google.android.gms.ads.mediation.MediationConfiguration; |
| 21 | +import com.google.android.gms.ads.mediation.VersionInfo; |
| 22 | +import com.google.android.gms.ads.mediation.rtb.RtbAdapter; |
| 23 | +import com.google.android.gms.ads.mediation.rtb.RtbSignalData; |
| 24 | +import com.google.android.gms.ads.mediation.rtb.SignalCallbacks; |
| 25 | +import java.util.List; |
| 26 | + |
| 27 | +/** An example {@link RtbAdapter} implementation for secure signal collection guidance. */ |
| 28 | +public class SampleAdapterSnippets extends RtbAdapter { |
| 29 | + private static final String TAG = "SampleAdapterSnippets"; |
| 30 | + private static final String SDK_VERSION_STRING = "1.2.3"; |
| 31 | + private static final String SAMPLE_SIGNAL_PLACEHOLDER = "your_sdk_secure_signal_string"; |
| 32 | + |
| 33 | + // [START initialize_adapter] |
| 34 | + @Override |
| 35 | + public void initialize( |
| 36 | + Context context, |
| 37 | + InitializationCompleteCallback initializationCompleteCallback, |
| 38 | + List<MediationConfiguration> configurations) { |
| 39 | + |
| 40 | + // Add your SDK initialization logic here. |
| 41 | + |
| 42 | + // Invoke the InitializationCompleteCallback once initialization completes. |
| 43 | + initializationCompleteCallback.onInitializationSucceeded(); |
| 44 | + } |
| 45 | + |
| 46 | + // [END initialize_adapter] |
| 47 | + |
| 48 | + // [START get_adapter_version_info] |
| 49 | + @Override |
| 50 | + public VersionInfo getVersionInfo() { |
| 51 | + // If your SDK implements this adapter in the same binary, return |
| 52 | + // the same version as your SDK (getSDKVersionInfo) here. |
| 53 | + |
| 54 | + // If you built a separate binary for this adapter, return |
| 55 | + // the adapter's version here. |
| 56 | + int major = 4; |
| 57 | + int minor = 5; |
| 58 | + int micro = 6; |
| 59 | + return new VersionInfo(major, minor, micro); |
| 60 | + } |
| 61 | + |
| 62 | + // [END get_adapter_version_info] |
| 63 | + |
| 64 | + // [START get_sdk_version_info] |
| 65 | + @Override |
| 66 | + public VersionInfo getSDKVersionInfo() { |
| 67 | + |
| 68 | + // Return your SDK's version string here. |
| 69 | + String versionString = SDK_VERSION_STRING; |
| 70 | + String[] splits = versionString.split("\\."); |
| 71 | + if (splits.length >= 3) { |
| 72 | + try { |
| 73 | + int major = Integer.parseInt(splits[0]); |
| 74 | + int minor = Integer.parseInt(splits[1]); |
| 75 | + int micro = Integer.parseInt(splits[2]); |
| 76 | + return new VersionInfo(major, minor, micro); |
| 77 | + } catch (NumberFormatException e) { |
| 78 | + // Fall through to log warning and return 0.0.0. |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + Log.w( |
| 83 | + TAG, |
| 84 | + String.format( |
| 85 | + "Unexpected SDK version format: %s. Returning 0.0.0 for SDK version.", versionString)); |
| 86 | + return new VersionInfo(0, 0, 0); |
| 87 | + } |
| 88 | + |
| 89 | + // [END get_sdk_version_info] |
| 90 | + |
| 91 | + // [START collect_signals] |
| 92 | + @Override |
| 93 | + public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCallbacks) { |
| 94 | + |
| 95 | + // Add your signal collection logic here. |
| 96 | + String signals = SAMPLE_SIGNAL_PLACEHOLDER; |
| 97 | + |
| 98 | + // Return the signals as a string to the Google Mobile Ads SDK. |
| 99 | + signalCallbacks.onSuccess(signals); |
| 100 | + } |
| 101 | + |
| 102 | + // [END collect_signals] |
| 103 | + |
| 104 | +} |
0 commit comments