From f088d1850f2b6147f22eeaa7c63998aca93c7e7e Mon Sep 17 00:00:00 2001 From: Sunil Kumar Reddy Kuna Date: Fri, 6 Sep 2024 13:26:04 +0530 Subject: [PATCH 1/6] Upgraded the SDK version to 10.7.7 --- README.md | 19 +++---- gradle.properties | 3 + gradle/wrapper/gradle-wrapper.properties | 2 +- samples/bannerSample/build.gradle | 30 +++------- samples/bannerSample/proguard-rules.pro | 26 +-------- .../bannerSample/src/main/AndroidManifest.xml | 11 ++-- .../java/com/inmobi/banner/PlacementId.java | 2 +- .../banner/sample/BannerAdsActivity.java | 2 - .../com/inmobi/banner/sample/BannerBase.java | 6 +- .../inmobi/banner/sample/NewsFeedAdapter.java | 10 ++-- .../main/res/layout/news_headline_view.xml | 4 +- .../src/main/res/values/colors.xml | 4 ++ .../src/main/res/values/styles.xml | 2 +- samples/customABSample/build.gradle | 31 +++++----- samples/customABSample/proguard-rules.pro | 22 +------ .../src/main/AndroidManifest.xml | 3 +- .../inmobi/customabsample/PlacementId.java | 4 +- samples/interstitialSample/build.gradle | 29 +++++----- samples/interstitialSample/proguard-rules.pro | 26 +-------- .../src/main/AndroidManifest.xml | 4 +- .../sample/InterstitialAdsActivity.java | 2 - .../interstitial/sample/PlacementId.java | 2 +- samples/nativeSample/build.gradle | 27 +++------ samples/nativeSample/proguard-rules.pro | 2 + .../nativeSample/src/main/AndroidManifest.xml | 10 ++-- .../java/com/inmobi/nativead/PlacementId.java | 2 +- sdk/ChangeLog.md | 57 +++++++++++++++++++ 27 files changed, 160 insertions(+), 182 deletions(-) diff --git a/README.md b/README.md index e3ec816..7806b92 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ InMobi SDK for Android ====================== -Modified: 16 February, 2023 +Modified: 30 August, 2024 -SDK Version: 10.5.4 +SDK Version: 10.7.7 Thanks for monetizing with InMobi! If you haven't already, [sign up](https://www.inmobi.com/user/index?locale=en_us#signup) for an account to start monetizing your app! @@ -20,7 +20,7 @@ repositories { mavenCentral() } dependencies { - implementation 'com.inmobi.monetization:inmobi-ads-kotlin:10.5.3' + implementation 'com.inmobi.monetization:inmobi-ads-kotlin:10.7.7' } ``` @@ -31,15 +31,14 @@ To download the latest SDK as a AAR, please visit [http://inmobi.com/sdk](https: **To continue integrating with the InMobi SDK, please see the [Integration Guidelines](https://support.inmobi.com/monetize/android-guidelines/) for Android.** ## New in this version - • Gradle 7.0 support - • Bug fixes + • Android 14 support ## Requirements -- Android 4.0.1 (API level 15) and higher -- androidx.browser -- androidx.appcompat -- androidx.recyclerview -- Picasso Library (picasso-2.8.jar) +- Android 4.0.1 (API level 16) and higher +- androidx.browser (Transitive dependency of InMobi SDK) +- androidx.appcompat (Not a dependency of SDK. Used only in Sample App) +- androidx.recyclerview (Not a dependency of SDK. Used only in Native Sample App) +- Picasso Library (picasso-2.8.jar) (Used in Native Ads) - **Recommended** Google Play Services 18.0.1 ## License diff --git a/gradle.properties b/gradle.properties index 915f0e6..10c8f5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,5 +16,8 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.defaults.buildfeatures.buildconfig=true android.enableJetifier=true +android.nonFinalResIds=false +android.nonTransitiveRClass=false android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e9eb5e9..86269ed 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip diff --git a/samples/bannerSample/build.gradle b/samples/bannerSample/build.gradle index 2ee62f9..b5aaca7 100644 --- a/samples/bannerSample/build.gradle +++ b/samples/bannerSample/build.gradle @@ -13,8 +13,9 @@ android { } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + applicationIdSuffix ".release" } debug { @@ -25,30 +26,17 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - lintOptions { - abortOnError false - } dexOptions { javaMaxHeapSize "4g" } + namespace 'com.inmobi.banner.sample' + lint { + abortOnError false + } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.aar']) - implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'androidx.annotation:annotation:1.0.0' - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.browser:browser:1.0.0' - implementation 'androidx.multidex:multidex:2.0.0' - - - implementation "com.inmobi.monetization:inmobi-ads-kotlin:$inmobiSdkVersion" - implementation "com.google.android.gms:play-services-ads-identifier:$playservicesadsidentifier" - implementation "com.google.android.gms:play-services-location:$playserviceslocation" - implementation "com.facebook.fresco:fresco:$fresco" - implementation "com.squareup.picasso:picasso:$picasso" - implementation "androidx.browser:browser:$browser" - implementation "com.google.android.gms:play-services-appset:$playservicesappset" - implementation "com.google.android.gms:play-services-tasks:$playservicestask" - +// implementation fileTree(dir: 'libs', include: ['*.aar']) + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation ('com.inmobi.monetization:inmobi-ads-kotlin:10.7.7') } diff --git a/samples/bannerSample/proguard-rules.pro b/samples/bannerSample/proguard-rules.pro index 61b8169..5b7c19c 100644 --- a/samples/bannerSample/proguard-rules.pro +++ b/samples/bannerSample/proguard-rules.pro @@ -16,27 +16,5 @@ # public *; #} --keepattributes SourceFile,LineNumberTable,InnerClasses --keep class com.inmobi.** { *; } --dontwarn com.inmobi.** --keep class com.google.android.gms.common.api.GoogleApiClient { public *; } --keep class com.google.android.gms.common.api.GoogleApiClient$* {public *;} --keep class com.google.android.gms.location.LocationServices {public *;} --keep class com.google.android.gms.location.FusedLocationProviderApi {public *;} --keep class com.google.android.gms.location.ActivityRecognition {public *;} --keep class com.google.android.gms.location.ActivityRecognitionApi {public *;} --keep class com.google.android.gms.location.ActivityRecognitionResult {public *;} --keep class com.google.android.gms.location.DetectedActivity {public *;} --keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{ - public *; -} --keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{ - public *; -} --dontwarn com.google.android.gms.** -# skip the Picasso library classes --keep class com.squareup.picasso.** {*;} --dontwarn com.squareup.picasso.** -# skip Moat classes --keep class com.moat.** {*;} --dontwarn com.moat.** +-dontwarn org.conscrypt.Conscrypt +-dontwarn org.conscrypt.OpenSSLProvider diff --git a/samples/bannerSample/src/main/AndroidManifest.xml b/samples/bannerSample/src/main/AndroidManifest.xml index 117918f..aab343a 100644 --- a/samples/bannerSample/src/main/AndroidManifest.xml +++ b/samples/bannerSample/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> @@ -12,9 +11,11 @@ - - #0a80d1 #808080 #d3d3d3 + + #3F51B5 + #303F9F + #FF4081 diff --git a/samples/bannerSample/src/main/res/values/styles.xml b/samples/bannerSample/src/main/res/values/styles.xml index 24a5e1f..a9d8889 100644 --- a/samples/bannerSample/src/main/res/values/styles.xml +++ b/samples/bannerSample/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - - - diff --git a/samples/customABSample/src/main/res/xml/network_security_config.xml b/samples/customABSample/src/main/res/xml/network_security_config.xml deleted file mode 100644 index 2328c2e..0000000 --- a/samples/customABSample/src/main/res/xml/network_security_config.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/FeedItemAdapter.java b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/FeedItemAdapter.java index beb19aa..1c444e1 100644 --- a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/FeedItemAdapter.java +++ b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/FeedItemAdapter.java @@ -1,9 +1,8 @@ package com.inmobi.nativead.sample.listview; -import android.app.Activity; import android.content.Context; import androidx.annotation.NonNull; -import android.util.DisplayMetrics; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,6 +14,7 @@ import android.widget.TextView; import com.inmobi.ads.InMobiNative; +import com.inmobi.media.ads.nativeAd.InMobiNativeViewData; import com.inmobi.nativead.sample.R; import com.inmobi.nativead.utility.FeedData.FeedItem; import com.squareup.picasso.Picasso; @@ -37,6 +37,8 @@ class FeedItemAdapter extends ArrayAdapter { //View type for Ad Feed - from InMobi (InMobi Native Strand) private static final int VIEW_TYPE_INMOBI_STRAND = 1; + private static final String TAG = FeedItemAdapter.class.getSimpleName(); + FeedItemAdapter(Context mContext, ArrayList mUsers) { super(mContext, R.layout.listitem, R.id.title, mUsers); this.mContext = mContext; @@ -65,7 +67,6 @@ public FeedItem getItem(int position) { @NonNull @Override - @SuppressWarnings("deprecation") public View getView(int position, View convertView, @NonNull ViewGroup parent) { final int itemViewType = getItemViewType(position); final FeedItem feedItem = getItem(position); @@ -123,35 +124,83 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) { viewHolder.action = (Button) convertView.findViewById(R.id.adAction); viewHolder.content = (FrameLayout) convertView.findViewById(R.id.adContent); viewHolder.ratingBar = (RatingBar) convertView.findViewById(R.id.adRating); + viewHolder.sponsored = (TextView) convertView.findViewById(R.id.adSponsored); + viewHolder.adChoice = (FrameLayout) convertView.findViewById(R.id.adChoice); convertView.setTag(viewHolder); } else { viewHolder = (AdViewHolder) convertView.getTag(); } - Picasso.get() - .load(inMobiNative.getAdIconUrl()) - .into(viewHolder.icon); + // Load icon image + if (inMobiNative.getAdIcon() != null && inMobiNative.getAdIcon().getUrl() != null) { + Picasso.get() + .load(inMobiNative.getAdIcon().getUrl()) + .into(viewHolder.icon); + } + + // Populate text views viewHolder.title.setText(inMobiNative.getAdTitle()); viewHolder.description.setText(inMobiNative.getAdDescription()); - viewHolder.action.setText(inMobiNative.getAdCtaText()); - - DisplayMetrics displayMetrics = new DisplayMetrics(); - ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - viewHolder.content.addView(inMobiNative.getPrimaryViewOfWidth(mContext, viewHolder.content, - parent, displayMetrics.widthPixels)); + viewHolder.action.setText(inMobiNative.getCtaText()); + viewHolder.sponsored.setText(inMobiNative.getAdvertiserName()); + + // Load media view + viewHolder.content.removeAllViews(); + final InMobiNative nativeAd = inMobiNative; + final FrameLayout mediaContainer = viewHolder.content; + viewHolder.content.post(new Runnable() { + @Override + public void run() { + View mediaView = nativeAd.getMediaView(); + if (mediaView != null) { + if (mediaView.getParent() != null) { + ((ViewGroup) mediaView.getParent()).removeView(mediaView); + } + int mediaHeight = mContext.getResources().getDimensionPixelSize(R.dimen.native_ad_media_height); + mediaView.setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + mediaHeight + )); + mediaContainer.addView(mediaView); + } else { + Log.d(TAG, "Media view is null for native ad"); + } + } + }); - float rating = inMobiNative.getAdRating(); - if (rating != 0) { + // Set rating if available + float rating = inMobiNative.getAdRating(); + if (rating > 0) { viewHolder.ratingBar.setRating(rating); + viewHolder.ratingBar.setVisibility(View.VISIBLE); + } else { + viewHolder.ratingBar.setVisibility(View.GONE); } - viewHolder.ratingBar.setVisibility(rating != 0 ? View.VISIBLE : View.GONE); - viewHolder.action.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - inMobiNative.reportAdClickAndOpenLandingPage(); + // Add AdChoice icon + viewHolder.adChoice.removeAllViews(); + View adChoiceIcon = inMobiNative.getAdChoiceIcon(); + if (adChoiceIcon != null) { + if (adChoiceIcon.getParent() != null) { + ((ViewGroup) adChoiceIcon.getParent()).removeAllViews(); } - }); + viewHolder.adChoice.addView(adChoiceIcon); + } + + // Build InMobiNativeViewData to register views for interaction + InMobiNativeViewData viewData = new InMobiNativeViewData.Builder((ViewGroup) convertView) + .setIconView(viewHolder.icon) + .setTitleView(viewHolder.title) + .setDescriptionView(viewHolder.description) + .setCTAView(viewHolder.action) + .setRatingView(viewHolder.ratingBar) + .setExtraViews(java.util.Arrays.asList(viewHolder.sponsored)) + .build(); + + // Register all interactive views with InMobi SDK for proper tracking and video playback. + // This is CRITICAL for video ads to function correctly - without this call, + // video will not play and clicks will not be tracked. + inMobiNative.registerViewForTracking(viewData); return convertView; } @@ -168,10 +217,10 @@ private static class ContentViewHolder { } private static class AdViewHolder { - TextView title, description; + TextView title, description, sponsored; ImageView icon; Button action; - FrameLayout content; + FrameLayout content, adChoice; RatingBar ratingBar; } } \ No newline at end of file diff --git a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/ListViewFeedFragment.java b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/ListViewFeedFragment.java index 2980446..4588e32 100644 --- a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/ListViewFeedFragment.java +++ b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/listview/ListViewFeedFragment.java @@ -17,6 +17,7 @@ import com.inmobi.ads.InMobiAdRequestStatus; import com.inmobi.ads.InMobiNative; import com.inmobi.ads.listeners.NativeAdEventListener; +import com.inmobi.ads.listeners.VideoEventListener; import com.inmobi.nativead.PlacementId; import com.inmobi.nativead.utility.FeedData; import com.inmobi.nativead.utility.SwipeRefreshLayoutWrapper; @@ -90,6 +91,24 @@ private void createStrands() { final InMobiNative nativeStrand = new InMobiNative(getActivity(), PlacementId.YOUR_PLACEMENT_ID_HERE, new StrandAdListener(position)); + // Add VideoEventListener for video playback + nativeStrand.setVideoEventListener(new VideoEventListener() { + @Override + public void onVideoCompleted(InMobiNative inMobiNative) { + Log.d(TAG, "Video completed"); + } + + @Override + public void onVideoSkipped(InMobiNative inMobiNative) { + Log.d(TAG, "Video skipped"); + } + + @Override + public void onAudioStateChanged(InMobiNative inMobiNative, boolean isMuted) { + Log.d(TAG, "Audio state changed to: " + (isMuted ? "muted" : "unmuted")); + } + }); + mStrands.add(nativeStrand); } } @@ -177,11 +196,6 @@ public void onAdFullScreenDismissed(InMobiNative inMobiNative) { Log.d(TAG, "Ad fullscreen dismissed."); } - @Override - public void onAdFullScreenWillDisplay(InMobiNative inMobiNative) { - Log.d(TAG, "Ad going fullscreen."); - } - @Override public void onAdFullScreenDisplayed(InMobiNative inMobiNative) { Log.d(TAG, "Ad fullscreen displayed."); @@ -197,11 +211,6 @@ public void onAdClicked(@NonNull InMobiNative inMobiNativeStrand) { Log.d(TAG, "Click recorded for ad at position:" + mPosition); } - @Override - public void onAdStatusChanged(@NonNull InMobiNative inMobiNative) { - Log.d(TAG, "Ad status changed"); - } - @Override public void onAdImpression(@NonNull InMobiNative inMobiNative) { Log.d(TAG, "onAdImpression"); diff --git a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/FeedsAdapter.java b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/FeedsAdapter.java index eaf3678..536d0fb 100644 --- a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/FeedsAdapter.java +++ b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/FeedsAdapter.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.inmobi.ads.InMobiNative; +import com.inmobi.media.ads.nativeAd.InMobiNativeViewData; import com.inmobi.nativead.sample.R; import com.inmobi.nativead.utility.FeedData.FeedItem; import com.squareup.picasso.Picasso; @@ -65,7 +66,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewT } @Override - @SuppressWarnings("deprecation") public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { FeedItem feedItem = mFeedItems.get(position); if (viewHolder instanceof FeedViewHolder) { @@ -90,30 +90,76 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { final AdViewHolder adViewHolder = (AdViewHolder) viewHolder; final InMobiNative inMobiNative = ((AdFeedItem) feedItem).mNativeStrand; - Picasso.get() - .load(inMobiNative.getAdIconUrl()) - .into(adViewHolder.icon); + // Load icon image + if (inMobiNative.getAdIcon() != null && inMobiNative.getAdIcon().getUrl() != null) { + Picasso.get() + .load(inMobiNative.getAdIcon().getUrl()) + .into(adViewHolder.icon); + } + + // Populate text views adViewHolder.title.setText(inMobiNative.getAdTitle()); adViewHolder.description.setText(inMobiNative.getAdDescription()); - adViewHolder.action.setText(inMobiNative.getAdCtaText()); - - DisplayMetrics displayMetrics = new DisplayMetrics(); - ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - adViewHolder.adContent.addView(inMobiNative.getPrimaryViewOfWidth(mContext, adViewHolder.adView, - adViewHolder.cardView, displayMetrics.widthPixels)); + adViewHolder.action.setText(inMobiNative.getCtaText()); + adViewHolder.sponsored.setText(inMobiNative.getAdvertiserName()); + + // Load media view + adViewHolder.adContent.removeAllViews(); + final InMobiNative nativeAd = inMobiNative; + final FrameLayout mediaContainer = adViewHolder.adContent; + adViewHolder.adContent.post(new Runnable() { + @Override + public void run() { + View mediaView = nativeAd.getMediaView(); + if (mediaView != null) { + if (mediaView.getParent() != null) { + ((ViewGroup) mediaView.getParent()).removeView(mediaView); + } + int mediaHeight = mContext.getResources().getDimensionPixelSize(R.dimen.native_ad_media_height); + mediaView.setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + mediaHeight + )); + mediaContainer.addView(mediaView); + } else { + android.util.Log.d("FeedsAdapter", "Media view is null for native ad"); + } + } + }); + // Set rating if available float rating = inMobiNative.getAdRating(); - if (rating != 0) { + if (rating > 0) { adViewHolder.ratingBar.setRating(rating); + adViewHolder.ratingBar.setVisibility(View.VISIBLE); + } else { + adViewHolder.ratingBar.setVisibility(View.GONE); } - adViewHolder.ratingBar.setVisibility(rating != 0 ? View.VISIBLE : View.GONE); - adViewHolder.action.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - inMobiNative.reportAdClickAndOpenLandingPage(); + // Add AdChoice icon + adViewHolder.adChoice.removeAllViews(); + View adChoiceIcon = inMobiNative.getAdChoiceIcon(); + if (adChoiceIcon != null) { + if (adChoiceIcon.getParent() != null) { + ((ViewGroup) adChoiceIcon.getParent()).removeAllViews(); } - }); + adViewHolder.adChoice.addView(adChoiceIcon); + } + + // Build InMobiNativeViewData to register views for interaction + InMobiNativeViewData viewData = new InMobiNativeViewData.Builder((ViewGroup) adViewHolder.adView) + .setIconView(adViewHolder.icon) + .setTitleView(adViewHolder.title) + .setDescriptionView(adViewHolder.description) + .setCTAView(adViewHolder.action) + .setRatingView(adViewHolder.ratingBar) + .setExtraViews(java.util.Arrays.asList(adViewHolder.sponsored)) + .build(); + + // Register all interactive views with InMobi SDK for proper tracking and video playback. + // This is CRITICAL for video ads to function correctly - without this call, + // video will not play and clicks will not be tracked. + inMobiNative.registerViewForTracking(viewData); } } @@ -122,9 +168,9 @@ private static class AdViewHolder extends RecyclerView.ViewHolder { View adView; ImageView icon; - TextView title, description; + TextView title, description, sponsored; Button action; - FrameLayout adContent; + FrameLayout adContent, adChoice; RatingBar ratingBar; AdViewHolder(Context context, View adCardView) { @@ -138,6 +184,8 @@ private static class AdViewHolder extends RecyclerView.ViewHolder { action = (Button) adView.findViewById(R.id.adAction); adContent = (FrameLayout) adView.findViewById(R.id.adContent); ratingBar = (RatingBar) adView.findViewById(R.id.adRating); + sponsored = (TextView) adView.findViewById(R.id.adSponsored); + adChoice = (FrameLayout) adView.findViewById(R.id.adChoice); cardView.addView(adView); } } diff --git a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/RecyclerFeedFragment.java b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/RecyclerFeedFragment.java index a48ff32..f2e219c 100644 --- a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/RecyclerFeedFragment.java +++ b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/recyclerview/RecyclerFeedFragment.java @@ -18,6 +18,7 @@ import com.inmobi.ads.InMobiAdRequestStatus; import com.inmobi.ads.InMobiNative; import com.inmobi.ads.listeners.NativeAdEventListener; +import com.inmobi.ads.listeners.VideoEventListener; import com.inmobi.nativead.PlacementId; import com.inmobi.nativead.sample.R; import com.inmobi.nativead.utility.FeedData; @@ -102,6 +103,25 @@ private void createStrands() { for (int position : mAdPositions) { final InMobiNative nativeStrand = new InMobiNative(getActivity(), PlacementId.YOUR_PLACEMENT_ID_HERE, new StrandAdListener(position)); + + // Add VideoEventListener for video playback + nativeStrand.setVideoEventListener(new VideoEventListener() { + @Override + public void onVideoCompleted(InMobiNative inMobiNative) { + Log.d(TAG, "Video completed"); + } + + @Override + public void onVideoSkipped(InMobiNative inMobiNative) { + Log.d(TAG, "Video skipped"); + } + + @Override + public void onAudioStateChanged(InMobiNative inMobiNative, boolean isMuted) { + Log.d(TAG, "Audio state changed to: " + (isMuted ? "muted" : "unmuted")); + } + }); + mStrands.add(nativeStrand); } } @@ -199,10 +219,6 @@ public void onAdFetchSuccessful(@NonNull InMobiNative inMobiNative, @NonNull AdM public void onAdFullScreenDismissed(InMobiNative inMobiNative) { } - @Override - public void onAdFullScreenWillDisplay(InMobiNative inMobiNative) { - } - @Override public void onAdFullScreenDisplayed(InMobiNative inMobiNative) { } @@ -216,10 +232,6 @@ public void onAdClicked(@NonNull InMobiNative inMobiNativeStrand) { Log.d(TAG, "Click recorded for ad at position:" + mPosition); } - @Override - public void onAdStatusChanged(@NonNull InMobiNative inMobiNative) { - } - @Override public void onAdImpression(@NonNull InMobiNative inMobiNative) { } diff --git a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/singlestrand/SingleNativeAdFragment.java b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/singlestrand/SingleNativeAdFragment.java index 56417fc..ec057cb 100644 --- a/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/singlestrand/SingleNativeAdFragment.java +++ b/samples/nativeSample/src/main/java/com/inmobi/nativead/sample/singlestrand/SingleNativeAdFragment.java @@ -22,6 +22,7 @@ import com.inmobi.ads.InMobiNative; import com.inmobi.ads.listeners.NativeAdEventListener; import com.inmobi.ads.listeners.VideoEventListener; +import com.inmobi.media.ads.nativeAd.InMobiNativeViewData; import com.inmobi.nativead.PlacementId; import com.inmobi.nativead.sample.R; import com.inmobi.nativead.utility.SwipeRefreshLayoutWrapper; @@ -46,7 +47,7 @@ public static String getTitle() { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_custom_integration, container, false); - mContainer = (ViewGroup) view.findViewById(R.id.container); + mContainer = view.findViewById(R.id.container); final SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayoutWrapper.getInstance(getActivity(), new SwipeRefreshLayoutWrapper.Listener() { @@ -77,10 +78,8 @@ public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); final View view = loadAdIntoView(mInMobiNative); - if (view != null) { - mContainer.removeAllViews(); - mContainer.addView(view); - } + mContainer.removeAllViews(); + mContainer.addView(view); } private void createStrands() { @@ -103,6 +102,18 @@ public void onAudioStateChanged(InMobiNative inMobiNative, boolean b) { super.onAudioStateChanged(inMobiNative, b); Log.d(TAG, "Audio state changed"); } + + @Override + public void onVideoStarted(InMobiNative inMobiNative) { + super.onVideoStarted(inMobiNative); + Log.d(TAG, "Video started"); + } + + @Override + public void onVideoResumed(InMobiNative inMobiNative) { + super.onVideoResumed(inMobiNative); + Log.d(TAG, "Video resumed"); + } }); } @@ -127,7 +138,6 @@ private void reloadAd() { loadAd(); } - @SuppressWarnings("deprecation") private View loadAdIntoView(@NonNull final InMobiNative inMobiNative) { View adView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_ad, null); @@ -137,30 +147,79 @@ private View loadAdIntoView(@NonNull final InMobiNative inMobiNative) { Button action = (Button) adView.findViewById(R.id.adAction); FrameLayout content = (FrameLayout) adView.findViewById(R.id.adContent); RatingBar ratingBar = (RatingBar) adView.findViewById(R.id.adRating); + TextView sponsored = (TextView) adView.findViewById(R.id.adSponsored); + FrameLayout adChoice = (FrameLayout) adView.findViewById(R.id.adChoice); + + // Load icon image + if (inMobiNative.getAdIcon() != null && inMobiNative.getAdIcon().getUrl() != null) { + Picasso.get() + .load(inMobiNative.getAdIcon().getUrl()) + .into(icon); + } - Picasso.get() - .load(inMobiNative.getAdIconUrl()) - .into(icon); + // Populate text views title.setText(inMobiNative.getAdTitle()); description.setText(inMobiNative.getAdDescription()); - action.setText(inMobiNative.getAdCtaText()); - - DisplayMetrics displayMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - content.addView(inMobiNative.getPrimaryViewOfWidth(getActivity(), content, mContainer, displayMetrics.widthPixels)); + action.setText(inMobiNative.getCtaText()); + sponsored.setText(inMobiNative.getAdvertiserName()); + + // Load media view with layout params + content.removeAllViews(); + final InMobiNative nativeAd = inMobiNative; + final FrameLayout mediaContainer = content; + content.post(new Runnable() { + @Override + public void run() { + View mediaView = nativeAd.getMediaView(); + if (mediaView != null) { + if (mediaView.getParent() != null) { + ((ViewGroup) mediaView.getParent()).removeView(mediaView); + } + int mediaHeight = getResources().getDimensionPixelSize(R.dimen.native_ad_media_height); + mediaView.setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + mediaHeight + )); + mediaContainer.addView(mediaView); + } else { + Log.d(TAG, "Media view is null for native ad"); + } + } + }); + // Set rating if available float rating = inMobiNative.getAdRating(); - if (rating != 0) { + if (rating > 0) { ratingBar.setRating(rating); + ratingBar.setVisibility(View.VISIBLE); + } else { + ratingBar.setVisibility(View.GONE); } - ratingBar.setVisibility(rating != 0 ? View.VISIBLE : View.GONE); - action.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mInMobiNative.reportAdClickAndOpenLandingPage(); + // Add AdChoice icon + adChoice.removeAllViews(); + View adChoiceIcon = inMobiNative.getAdChoiceIcon(); + if (adChoiceIcon != null) { + if (adChoiceIcon.getParent() != null) { + ((ViewGroup) adChoiceIcon.getParent()).removeAllViews(); } - }); + adChoice.addView(adChoiceIcon); + } + + // Build InMobiNativeViewData to register views for interaction + InMobiNativeViewData viewData = new InMobiNativeViewData.Builder((ViewGroup) adView) + .setIconView(icon) + .setTitleView(title) + .setDescriptionView(description) + .setCTAView(action) + .setRatingView(ratingBar) + .setExtraViews(java.util.Arrays.asList(sponsored)) + .build(); + + // Register all interactive views with InMobi SDK for proper tracking and video playback. + // This is CRITICAL for video ads to function correctly - without this call, + // video will not play and clicks will not be tracked. + inMobiNative.registerViewForTracking(viewData); return adView; } @@ -174,13 +233,9 @@ public StrandAdListener() { @Override public void onAdLoadSucceeded(@NonNull InMobiNative inMobiNative, @NonNull AdMetaInfo adMetaInfo) { - //Pass the old ad view as the first parameter to facilitate view reuse. + Log.d(TAG, "Ad Load succeeded with bid " + adMetaInfo.getBid()); View view = loadAdIntoView(inMobiNative); - if (view == null) { - Log.d(TAG, "Could not render Strand!"); - } else { - mContainer.addView(view); - } + mContainer.addView(view); } @Override @@ -195,19 +250,17 @@ public void onAdFetchSuccessful(@NonNull InMobiNative inMobiNative, @NonNull AdM @Override public void onAdFullScreenDismissed(InMobiNative inMobiNative) { - } - - @Override - public void onAdFullScreenWillDisplay(InMobiNative inMobiNative) { - Log.d(TAG, "Ad going fullscreen."); + Log.d(TAG, "Ad fullscreen dismissed."); } @Override public void onAdFullScreenDisplayed(InMobiNative inMobiNative) { + Log.d(TAG, "Ad is fullscreen."); } @Override public void onUserWillLeaveApplication(InMobiNative inMobiNative) { + Log.d(TAG, "User will leave application."); } @Override @@ -215,13 +268,9 @@ public void onAdClicked(@NonNull InMobiNative inMobiNative) { Log.d(TAG, "Ad clicked"); } - - @Override - public void onAdStatusChanged(@NonNull InMobiNative inMobiNative) { - } - @Override public void onAdImpression(@NonNull InMobiNative inMobiNative) { + Log.d(TAG, "Ad impression logged"); } } diff --git a/samples/nativeSample/src/main/res/layout/layout_ad.xml b/samples/nativeSample/src/main/res/layout/layout_ad.xml index 0462b7c..0becc9e 100644 --- a/samples/nativeSample/src/main/res/layout/layout_ad.xml +++ b/samples/nativeSample/src/main/res/layout/layout_ad.xml @@ -15,11 +15,20 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> + + diff --git a/samples/nativeSample/src/main/res/values/dimens.xml b/samples/nativeSample/src/main/res/values/dimens.xml index 7aaab54..af26f9a 100644 --- a/samples/nativeSample/src/main/res/values/dimens.xml +++ b/samples/nativeSample/src/main/res/values/dimens.xml @@ -17,4 +17,5 @@ 5dp 16dp + 300dp diff --git a/sdk/ChangeLog.md b/sdk/ChangeLog.md index bae6fc9..7d0533b 100644 --- a/sdk/ChangeLog.md +++ b/sdk/ChangeLog.md @@ -1,6 +1,100 @@ InMobi Monetization SDK ChangeLog for Android ============================================= +## Build 11.0.0 [9/Oct/2025] + • Upgraded support for native ads + • Bug Fixes and Enhancements + • APIs Removed + InMobiNative + - public String getAdIconUrl() + - public String getAdLandingPageUrl() + - public boolean isAppDownload() + - public JSONObject getCustomAdContent() + - public View getPrimaryViewOfWidth(Context context, View convertView, ViewGroup parent, int viewWidthInPixels) + - public void reportAdClickAndOpenLandingPage() + NativeAdEventListener + - public void onAdReceived(@NonNull InMobiNative ad) + - public void onAdFullScreenWillDisplay(@NonNull InMobiNative ad) + - public void onAdImpressed(@NonNull InMobiNative ad) + - public void onAdStatusChanged(@NonNull InMobiNative nativeAd) + + • APIs Added + New Class Added : InMobiNativeImage + New Class Added : InMobiNativeViewData + New Class Added : MediaView + InMobiNative + - public InMobiNativeImage getAdIcon() + - public String getAdvertiserName() + - public View getAdChoiceIcon() + - public void registerViewForTracking(InMobiNativeViewData viewData) + - public void unTrackViews() + - public MediaView getMediaView() + - public boolean isVideo() + - public String getCreativeId() + - public JSONObject getAdContent() + +## Build 10.8.8 [26/Sep/2025] + • Simplified PPS integration + • Bug Fixes + +## Build 10.8.7 [30/Jul/2025] + • Bug Fixes + +## Build 10.8.6 [28/Jul/2025] + • Updated OMSDK to 1.5.5 + • Performance Enhancements + • Bug Fixes + +## Build 10.8.5 (Internal Release) [03/July/2025] + • 10.8.2 and 10.8.3 changes merged into 10.8.4 + • Bug Fixes + +## Build 10.8.4 (Internal Release) [06/June/2025] + • Native 1.2 Release + +## Build 10.8.3 [30/Apr/2025] + • Added support for MRAID 3.0 + - Includes support for exposureChange, MRAID_ENV, audioVolumeChange APIs + • Minor upgrades in ad experience + • Upgraded Open Measurement ( OM ) SDK to 1.5.2 + • Improved memory management + • Deprecation of getSignals and PreloadManager API + - APIs Deprecated + • InMobiBanner + public String getSignals() + public PreloadManager getPreloadManager() + • InMobiInterstitial + public String getSignals() + public PreloadManager getPreloadManager() + • InMobiNative + public String getSignals() + public PreloadManager getPreloadManager() + • Upgraded the minSdkVersion from 16 to 19. + • Upgraded the dependency "androidx.browser" from 1.2.0 to 1.8.0. + • Bug Fixes + +## Build 10.8.2 [28/Feb/2025] + • Added support for Android 35 + • Bug Fixes + +## Build 10.8.1 (Internal Release) [15/Jan/2024] + • Bug Fixes + +## Build 10.8.0 [13/Nov/2024] + • Bug Fixes + +## Build 10.7.9 (Internal Release) [15/Oct/2024] + • Glance POM Support + +## Build 10.7.8 [04/Oct/2024] + • Support for Publisher Signals. + - APIs added + • InMobiSdk + fun putPublisherSignals(signals: Map?) + fun getPublisherSignals(): Map? + fun resetPublisherSignals() + • Bug Fixes + ## Build 10.7.7 [30/Aug/2024] • Updated TargetVersion support to Android 14 • Bug Fixes diff --git a/settings.gradle b/settings.gradle index 4cae036..063393b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':samples:bannerSample', ':samples:interstitialSample', ':samples:nativeSample', ':samples:customABSample' \ No newline at end of file +include ':samples:bannerSample', ':samples:interstitialSample', ':samples:nativeSample' \ No newline at end of file