Posts tagged with android

I added a single Native ad to my application, but on different devices, ads, especially videos, come with a delay, on the emulator the video is not shown at all. I know that you can somehow preload ads, but I don’t know how to do it, please explain to me.

Here is my code:

class Fragment(private var index: Int, private var adsId: String) : Fragment() {     var currentNativeAd: UnifiedNativeAd? = null     lateinit var adLoader: AdLoader     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {         val view = inflater.inflate(R.layout.fragment, container, false)         return view     }     override fun onActivityCreated(savedInstanceState: Bundle?) {         super.onActivityCreated(savedInstanceState)         val unifiedNativeAdView = layoutInflater.inflate(R.layout.native_ad_layout, null) as UnifiedNativeAdView         val nativeAdLayout = view!!.findViewById<FrameLayout>(R.id.id_native_ad)         val adLoader = AdLoader.Builder(activity, adsId).forUnifiedNativeAd { unifiedNativeAd -> (unifiedNativeAd)             mapUnifiedNativeAdToLayout(unifiedNativeAd, unifiedNativeAdView)             nativeAdLayout.removeAllViews()         }.withAdListener(object : AdListener() {             // Code to be executed when an ad request fails.             override fun onAdLoaded() {                 super.onAdLoaded()                 if (!adLoader.isLoading) {                   nativeAdLayout.addView(unifiedNativeAdView)                 }             }             override fun onAdFailedToLoad(errorCode: Int) {                Toast.makeText(applicationContext, "Ad failed to load! error code: $errorCode", Toast.LENGTH_SHORT).show()             }             override fun onAdClosed() {                 nativeAdLayout.removeAllViews()             }         }).build()         adLoader.loadAd(AdRequest.Builder().build())         }     fun mapUnifiedNativeAdToLayout(adFromGoogle: UnifiedNativeAd, myAdView: UnifiedNativeAdView) {         currentNativeAd?.destroy()         currentNativeAd = adFromGoogle         val mediaView: MediaView = myAdView.findViewById(R.id.ad_media)         myAdView.mediaView = mediaView         myAdView.bodyView = myAdView.findViewById(R.id.ad_body)         if (adFromGoogle.body == null) {             myAdView.bodyView.visibility = View.GONE         } else {             (myAdView.bodyView as TextView).text = adFromGoogle.body         }         myAdView.setNativeAd(adFromGoogle)         val vc = adFromGoogle.videoController         if (vc.hasVideoContent()) {             vc.videoLifecycleCallbacks = object : VideoController.VideoLifecycleCallbacks() {                 override fun onVideoEnd() {                     super.onVideoEnd()                 }             }         }      }     override fun onDestroy() {         currentNativeAd?.destroy()         super.onDestroy()     } } 

native_ad_layout.xml

<?xml version="1.0" encoding="utf-8"?> <com.google.android.gms.ads.formats.UnifiedNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_gravity="bottom">     <LinearLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="center"         android:orientation="vertical">         <RelativeLayout             android:layout_width="match_parent"             android:layout_height="match_parent">             <LinearLayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:weightSum="2"                 android:orientation="vertical">                 <com.google.android.gms.ads.formats.MediaView                     android:id="@+id/ad_media"                     android:layout_width="match_parent"                     android:layout_height="0dp"                     android:padding="@dimen/_8sdp"                     android:layout_gravity="center"                     android:layout_weight="2"                     android:background="#fff" />                 <TextView                     android:id="@+id/ad_body"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:fontFamily="@font/sf_pro_display_regular"                     android:gravity="center"                     android:text="body of ad"                     android:textSize="14sp" />             </LinearLayout>         </RelativeLayout>          </LinearLayout> </com.google.android.gms.ads.formats.UnifiedNativeAdView> 

In a fragment.xml, just a FrameView for the ad.

I'm developing an Android app that creates a whitelist of over 400 contacts and groups of WhatsApp to send them a scheduled message. I found an API to send a message using WhatsApp by passing the message and the receipt contact (person or group), but I didn't find another API to get all group ids of WhatsApp.

How to retrieve all WhatsApp groups' ids, using Android Java?

I don't really know if im in the correct forum, but please if not, point me in the right direction.

I have a little problem: I have setted up a campaing for downloads of the App from a client (A corporation) this campaing is setted on the objective of the first_open(Android) on firebase. I've talked with my associated account executive and he tells me we should also have another campaing with a first_open (iOS) objective. Here is where the problem starts. The google executive tells me we should have an event called first_open (iOS) which should be a separated event from first_open (Android), but I can't find this. It's not listed as an event on firebase nor google analytics web + app, I've tryed creating this event on my own but can't seem to get it working.

If I go into firebase conversions or events, I can only see one first_open event, that I can use a filter on, and see Android/iOS independently, but I can't seem to export it in separate to Google Ads conversions. There are some events called something like this, but they show 0 conversions.

If I can use the filter on firebase to see iOS first opens, how come I cant seem to see this conversions in Ads??

Also, how come I can extract this "Conversion events" from firebase, through google ads, but I'm not able to see them on firebase nor analytics?

Thank you!

I use the library 'com.google.android.gms: play-services-ads: 19.1.0' for advertising, I create a banner as follows: https://developers.google.com/admob/android/banner/adaptive so that it always turned out to be the full width of the screen and everything works well, but sometimes black lines appear enter image description here

please tell me how can I remove them? I tried transparent styles and setting the background color,

android: theme = "@ style / TranslucentTheme" android: background = "@ color / transparent"

In xml and through the code, and nothing helps.

Recently, I made an android app. After that, I have opened my account in AdMob and entered my app. I have got an App ID and Unit ID. For the first time, I tested my App with testing ID codes from developers.google.com. It worked well. But I have put IDs which are from AdMob in my codes. As a result, It is not displaying. Here is my Manifest.xml file

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     package="com.example.myapp2">     <uses-permission android:name="android.permission.INTERNET" />     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />     <application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="Lotin-Kirill Converter"         android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"         android:theme="@style/AppTheme">         <meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx"/>         <activity             android:name="com.example.myapp2.Splash"             android:screenOrientation="portrait"             tools:ignore="LockedOrientationActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <activity             android:name="com.example.myapp2.MainActivity">         </activity>         <meta-data             android:name="preloaded_fonts"             android:resource="@array/preloaded_fonts" />     </application> </manifest> 

It is build.gradle(:app)

apply plugin: 'com.android.application' android {     compileSdkVersion 29     buildToolsVersion "29.0.3"     defaultConfig {         applicationId "com.example.myapp2"         minSdkVersion 16         targetSdkVersion 29         versionCode 1         versionName "1.0"         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'         }     } } dependencies {     implementation fileTree(dir: 'libs', include: ['*.jar'])     implementation 'androidx.appcompat:appcompat:1.1.0'     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'     implementation 'com.google.android.gms:play-services-ads:19.2.0'     testImplementation 'junit:junit:4.12'     androidTestImplementation 'androidx.test.ext:junit:1.1.1'     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } 

Here is MainActivity.java

package com.example.myapp2; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.os.StrictMode; import android.view.View; import android.webkit.WebView; import android.widget.Toast; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; public class MainActivity extends AppCompatActivity {     WebView view;     AdView mAdview;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         MobileAds.initialize(this, new OnInitializationCompleteListener() {             @Override             public void onInitializationComplete(InitializationStatus initializationStatus) {             }         });         mAdview = (AdView)findViewById(R.id.adView);         AdRequest adRequest = new AdRequest.Builder().build();         mAdview.loadAd(adRequest);         StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();         StrictMode.setVmPolicy(builder.build());         view = (WebView) this.findViewById(R.id.webView);         view.getSettings().setJavaScriptEnabled(true);         view.getSettings().setDatabaseEnabled(true);         view.getSettings().setDatabasePath("/data/data/" + view.getContext().getPackageName() + "/databases/");         view.getSettings().setDomStorageEnabled(true);         view.getSettings().setLoadsImagesAutomatically(true);         view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);         view.loadUrl("file:///android_asset/test.html");     }     boolean doubleBackToExitPressedOnce = false;     @Override     public void onBackPressed() {         if (doubleBackToExitPressedOnce) {             new AlertDialog.Builder(this)                     .setTitle("Lotin-Kirill Converter.")                     .setMessage("Dasturdan chiqmoqchimisiz?")                     .setPositiveButton("Ha",                             new DialogInterface.OnClickListener() {                                 @Override                                 public void onClick(DialogInterface dialog,                                                     int which) {                                     finish();                                 }                             }).setNegativeButton("Yo'q", null).show();             return;         }         this.doubleBackToExitPressedOnce = true;         Toast.makeText(this, "Iltimos, Dasturdan chiqish uchun yana bir marta bosing!", Toast.LENGTH_SHORT).show();         new Handler().postDelayed(new Runnable() {             @Override             public void run() {                 doubleBackToExitPressedOnce=false;             }         }, 2000);     } } 

It is activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     tools:context=".MainActivity">     <WebView         android:id="@+id/webView"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent">     </WebView>     <com.google.android.gms.ads.AdView         android:id="@+id/adView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentBottom="true"         android:layout_centerHorizontal="true"         app:adSize="BANNER"         app:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx" /> </RelativeLayout> 

If you find my mistake, Please help me! Thank you for your attention!