Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by demilp · Aug 04, 2014 at 07:37 PM · androidpluginadmobunity analytics

App stops working as soon it starts.

Hi, I wrote my own plugin for Google Admob and Analytics, but as soon as the app starts, it closes.

This is the plugin code:

 package com.demilp.plugins;
 
 import android.os.Bundle;
 import android.view.Gravity;
 import android.widget.FrameLayout.LayoutParams;
 import android.widget.LinearLayout;
 
 import com.google.android.gms.ads.*;
 import com.google.android.gms.analytics.GoogleAnalytics;
 import com.google.android.gms.analytics.HitBuilders;
 import com.google.android.gms.analytics.Tracker;
 import com.unity3d.player.UnityPlayerNativeActivity;
 
 public class Plugins extends UnityPlayerNativeActivity  {
 
     //Variables de Analytics
     private Tracker tracker;
     
     //Variables de AdMob
     private AdView adView;
     private InterstitialAd interstitial;
     //Mi Nexus 5 ID 04911cc734379b2b
     
     
     //Metodos Compartidos
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     }
     
     @Override
     protected void onStart() {
         super.onStart();
         GoogleAnalytics.getInstance(this).reportActivityStart(this);
     }
 
     @Override
     protected void onResume() {
         super.onResume();
         if (adView != null) {
             adView.resume();
         }
     }
 
       @Override
       protected void onPause() {
         if (adView != null) {
           adView.pause();
         }
         super.onPause();
       }
     
     
     @Override
     protected void onStop() {
         super.onStop();
         GoogleAnalytics.getInstance(this).reportActivityStop(this);
     }
     
     @Override
     protected void onDestroy() {
         DestroyAdBanner();
         super.onDestroy();
     }
     
     
     //Metodos de Analytics
     public void InitAnalytics(String propertyID)
     {
         if(tracker == null)
         {
             GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
             tracker = analytics.newTracker(propertyID);
         }
         
     }
     
     
     public void SendScreen(String screenName)
     {
         tracker.setScreenName(screenName);
         tracker.send(new HitBuilders.AppViewBuilder().build());
     }
     
     public void SendEvent(String category, String action, String label, long value)
     {
         tracker.send(new HitBuilders.EventBuilder()
         .setCategory(category)
         .setAction(action)
         .setLabel(label)
         .setValue(value)
         .build());
     }
     public void SendEvent(String category, String action, String label)
     {
         tracker.send(new HitBuilders.EventBuilder()
         .setCategory(category)
         .setAction(action)
         .setLabel(label)
         .build());
     }
     public void SendEvent(String category, String action)
     {
         tracker.send(new HitBuilders.EventBuilder()
         .setCategory(category)
         .setAction(action)
         .build());
     }
     
     public void SendTiming(String category, long value, String name, String label)
     {
         tracker.send(new HitBuilders.TimingBuilder()
         .setCategory(category)
         .setValue(value)
         .setVariable(name)
         .setLabel(label)
         .build());
     }
     public void SendTiming(String category, long value, String name)
     {
         tracker.send(new HitBuilders.TimingBuilder()
         .setCategory(category)
         .setValue(value)
         .setVariable(name)
         .build());
     }
     public void SendTiming(String category, long value)
     {
         tracker.send(new HitBuilders.TimingBuilder()
         .setCategory(category)
         .setValue(value)
         .build());
     }
 
     
     //Metodos de AdMob    
     public void CreateAdBanner(String adUnitID, int adSize, String testDeviceID, boolean isTesting){
         // Create an ad.
         
         //adView.setX([float x]);
         //adView.sety([float y]);
 
         adView = new AdView(this);
         
         switch (adSize){
             case 0:
                 adView.setAdSize(AdSize.BANNER);
                 break;
             case 1:
                 adView.setAdSize(AdSize.FULL_BANNER);
                 break;
             case 2:
                 adView.setAdSize(AdSize.LEADERBOARD);
                 break;
             case 3:
                 adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
                 break;
             case 4:
                 adView.setAdSize(AdSize.SMART_BANNER);
                 break;
             case 5:
                 adView.setAdSize(AdSize.WIDE_SKYSCRAPER);
                 break;
             default:
                 adView.setAdSize(AdSize.SMART_BANNER);
                 break;
         }
         
         
         adView.setAdUnitId(adUnitID);
 
 
         
         // Create an ad request. Check logcat output for the hashed device ID to
         // get test ads on a physical device.
         AdRequest adRequest;
         if(isTesting){
             adRequest = new AdRequest.Builder()
                 .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                 .addTestDevice(testDeviceID)
                 .build();
         }else{
             adRequest = new AdRequest.Builder().build();
         }
         // Start loading the ad in the background.
         adView.loadAd(adRequest);
     }
     
     
     
     
     public void ShowAdBanner(int gravity){
         
         if(adView != null){
             LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
             
             
             LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
             
             switch(gravity){
             case 0:
                 layout.setGravity(Gravity.NO_GRAVITY);
                 break;
             case 1:
                 layout.setGravity(Gravity.CENTER_HORIZONTAL);
                 break;
             case 2:
                 layout.setGravity(Gravity.LEFT);
                 break;
             case 3:
                 layout.setGravity(Gravity.RIGHT);
                 break;
             case 4:
                 layout.setGravity(Gravity.FILL_HORIZONTAL);
                 break;
             case 5:
                 layout.setGravity(Gravity.CENTER_VERTICAL);
                 break;
             case 6:
                 layout.setGravity(Gravity.CENTER);
                 break;
             case 7:
                 layout.setGravity(Gravity.TOP);
                 break;
             case 8:
                 layout.setGravity(Gravity.BOTTOM);
                 break;
             case 9:
                 layout.setGravity(Gravity.FILL_VERTICAL);
                 break;
             }
             
             
             if(layout.indexOfChild(adView) >= 0){
                 adView.setLayoutParams(params);
                 layout.addView(adView);
             }
         }
     }
     
     
     
     
     public void HideAdBanner(){
         if(adView != null){
             LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
             layout.removeView(adView);
         }
     }
     
     public void DestroyAdBanner(){
         if (adView != null) {
             HideAdBanner();
             adView.destroy();
         }
     }
     
     public void CreateAdInterstitial(String adUnitID, String testDeviceID){
         interstitial = new InterstitialAd(this);
         interstitial.setAdUnitId(adUnitID);
 
         // Create ad request.
         AdRequest.Builder adRequestBuilder = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("testDeviceID");
 
         //Add listener
         interstitial.setAdListener(new AdListener() {
             @Override
             public void onAdLoaded() {
                 ShowAdInterstitial();
             }
 
 
         });
         
         
         // Begin loading your interstitial.
         interstitial.loadAd(adRequestBuilder.build());
     }
     
     private void ShowAdInterstitial() {
         if (interstitial.isLoaded()) {
             
             interstitial.show();
             
         }
     }
     
 }
 

I replace the activity in the manifest with com.demilp.plugins.Plugins and copy google-play-services.jar to Assets/Plugins/Android. Am i missing something?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liortal · Aug 04, 2014 at 07:59 PM 0
Share

Are you also placing the compiled JAR version of your activity under Assets/Plugins/Android ? Also, please attach the logcat output of the game crashing when you test it (on the device or emulator, whichever you used).

avatar image demilp · Aug 04, 2014 at 08:28 PM 0
Share

Yes, i placed it in Assets/Plugins/Android. I'm trying to use other plugins I wrote, but it seems they are compiling wrongly. If you have any notion of compiling plugins, would you give it a try?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Where can I find Admob android plugin? 2 Answers

play sevices resolver not present in assets. 0 Answers

Hide/Show Admob View Android plugin 0 Answers

Editing Android Plugins 0 Answers

Using Ad plugins on Android leads to extra crashes 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges