user2952821
user2952821

Reputation: 753

Intent hiding adview in android app

Following is my code -

protected void onCreate(Bundle savedInstanceState) 
{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView adview = (AdView) this.findViewById(R.id.adView);
        AdRequest adrequest = new AdRequest.Builder().build();
        adview.loadAd(adrequest);
        String url = "https://m.youtube.com/channel/UCJjkahdjnbsadjsiaojdoAg";

        Intent intent=null;
        try 
        {
            intent =new Intent(Intent.ACTION_VIEW);
            intent.setPackage("com.google.android.youtube");
            intent.setData(Uri.parse(url));
            startActivity(intent);
        } 
        catch (ActivityNotFoundException e) 
        {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
        }   
}

When I remove all intent part and keep only adview lines I am able to see admob banner advertisement. But When I add the intent and start activity I do not see any ad and in logcat it shows

12-26 23:53:34.399: I/Ads(536): Scheduling ad refresh 30000 milliseconds from now.
12-26 23:53:34.409: I/Ads(536): Ad finished loading.
12-26 23:54:04.410: I/Ads(536): Ad is not visible. Not refreshing ad.

I want to place intent after adview OR adview over intent.

How can I achieve this ???

Do I have to change or add any view for intent ?? how ??

Upvotes: 2

Views: 179

Answers (1)

petey
petey

Reputation: 17140

In your current code, you show an ad in your activity, then quickly start another activity (the ondevice Youtube application) which then, backgrounds your applications.

In order to play a video from YouTube while showing YOUR ad and not be backgrounded, you will want to include and implement the android Youtube Player into your application.

Sample applications that do such a thing are here : https://developers.google.com/youtube/android/player/sample-applications

Upvotes: 1

Related Questions