Add settings and ads to your splash screen.

Discussion in 'Tutorials' started by Eraste, Sep 12, 2013.

  1. Eraste Seasoned Vet

    Member Since:
    Jan 26, 2013
    Message Count:
    159
    Likes Received:
    76
    Trophy Points:
    100
    Hello all, I Want to share how I added the settings menu of my live wallpapers directly to the splash screen also how to ad in LEADBOLT ads. I only use leadbolt so I cannot comment on any other ad company's integration. All of this code is done with the latest version of ECLIPSE and ANDROID SDK tools installed.

    First off you need a working splash screen tutorial can be found here:
    http://www.livewallpapercreator.com/community/index.php?threads/adding-a-splash-activity.412/

    After your splash screen is up and running adding things to it is very simple. Leadbolt ads require the least amount of code and permissions to run this is why I chose them.

    Adding settings menu to your splash screen via a second button:

    1st: Locate your splash.xml file that your created with your splash screen and open it, copy the entire button lines of code and paste them directly below the first button. Next you will need to change the newly pasted button codes id. It can be whatever you want to keep it simple I use button2, so your newly pasted button code should look like this:
    Code (text):
    <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="30dp"
            android:onClick="sendMessage"
            android:text="@string/button2text"
            android:textSize="20sp" />
    as you can see you will also need to change the android:text name to a new name containing the information you want displayed on the button, I keep it simple again and put button2text.

    You will see some errors but do not worry we will fix them. Open your strings.xml file and under the last string in general settings or wherever you want add this line:
    Code (text):
    <string name="button2text">Live Wallpaper Settings</string>
    hit save.

    The errors in your splash.xml file should now go away. You can now save your splash.xml file.

    Next open your Splash.java file.

    We will now incorporate the settings into the Splash class.

    Before the first @override near the bottom of the file insert this code:
    Code (text):
    public void sendMessage(View view)
        {
            Intent intent = new Intent(Splash.this, LiveWallpaperSettings.class);
            startActivity(intent);
        }
    Hit the save button, Thats it settings will now open from the splash screen.


    Now for implementation of ads. This is actually easier than notification ads since you do not need anything but 2 lines of code!!!!!!!! per ad.

    These are the only permissions you need in your manifest file:
    Code (text):
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
     
    Then just as before create your app SDK in the leadbolt portal only checking ap ads, uncheck notification and icon.

    Then in the leadbolt under your app click add ad button and design and crate a banner ad and interestinal ad how you would like.

    Download your generated SDK and copy the .jar file that is in the zipped folder (it will have a wierd name usually a bunch of letters or numbers like this: com.uhjkkenndnd.jar) to your desktop. If you do not have a libs folder in your project in eclipse add one now. Then add the .jar file to the libs folder.

    Right click on the project name ( very top folder) and click properties, then java build path, then add jars, locate your newly added .jar file and add it. Click ok to exit properties.

    After you have done this you are ready to add the ads to your splash screen. Open the Splash.java file

    After this line:
    Code (text):
    setContentView(R.layout.splash);
    Insert your ad code:
    Code (text):
    AdController myController = new AdController(this, "YOUR_AD_CODE");
            myController.loadAd();
            AdController myController1 = new AdController(this, "YOUR_AD_CODE");
            myController1.loadAd();
    Replace YOUR_AD_CODE with the code you get from the ad in the leadbolt portal. The way I did it was the first one is the banner ( mine shows at bottom) ad then the second is the interestinal ad. This is all you need to implement ads. You can have as many or as less as you would like for instance you could have 2 banners ( one at top and bottom) and then one interestinal.

    For instance if you wanted to ad a second banner at the top if your first one is on the bottom, design a new one in the leadbolt portal for the top of the screen and add this line below those two:
    Code (text):
    AdController myController2 = new AdController(this, "YOUR_AD_CODE");
                  myController2.loadAd();
    You simply have to increase the number after myController each time you ad a new ad. So you can see you would now have 3 ads running when a user opens the splash screen:
    1 banner at the bottom: myController
    1 banner at the top: myController2
    1 interestinal ad: myController1

    Besides the permissions for leadbolt you should not need to add anything else to your manifest since the livewallpapersettings activity is already there. You should be good to go now. Save everything if you havent and build your app and test it.

    When you click the button in the app drawer your splash screen will open then approximately 3-5 seconds later the ads should appear, if they have not appeared within 8 seconds something went wrong go back and check your code.



    NEW!
    You can add leadbolt interestinal ads straight to the settings menu, simply add your
    Code (text):
    AdController myController2 = new AdController(this, "YOUR_AD_CODE");
                  myController2.loadAd();
    Remember to change the number after myController to whatever yours is and add your own ad code!

    code under these lines in the LiveWallpaperSettings.java file:
    Code (text):
    @Override
        protected void onCreate(Bundle b) {
            super.onCreate(b);
    So your ad code would be pasted below the super.onCreate(b); line. Simple as that. So if your not getting the splash screen down. Add the permissions, SDK, and this code to your LiveWallpaperSettings.java file to have ads in the settings menu.

    I have a button to the settings menu from the splash screen so a user sees an add when they open the splash screen, go into settings the manual way ( through androids multiple menus), or open settings from the splash screen. Good luck.
  2. fatos LWC Major

    Member Since:
    Apr 2, 2013
    Message Count:
    268
    Likes Received:
    73
    Trophy Points:
    200
    Thanks Eraste this was one of the best tutorials in the forum. I completed all of it without any problems. Your tutorial was perfectly explained (in details) and you saved yourself from lot of questions :).

    When new Leadbolt Sdk comes out I wish it could be well explained like this tutorial.

    Thanks again.
    Eraste likes this.
  3. Eraste Seasoned Vet

    Member Since:
    Jan 26, 2013
    Message Count:
    159
    Likes Received:
    76
    Trophy Points:
    100
    I don't see why the new SDK will be any different as far as implementation goes. Since we will not use notifications/icons anymore this method should still work. They are going to release a new SDK however we still wont have icons or notifications ( even if they say the sdk is compliant it cannot be if it contains icons or notifications as Google play's policy specifically states advertisement cannot be placed anywhere on the users device IE: homescreen, notification area, etc). All ads must be contained "inside" the application. I will wait and see what they offer but dont forget in the leadbolt portal you can create all different types of ads even audio ads!

    I am currently working on the "pause" "resume" function of the ads offered by leadbolt.
    With this users would have a button either in the splash screen or settings menu they could turn ads on or off. This is great because if a user doesn't want to see an ad every single time they enter the settings menu they will have the option to turn them off! Meaning Bad reviews for ads should be limited since the user can control them. If I get that working I will post it here and share with you guys.
    Joshua likes this.
  4. Friendlyspeaking Active Member

    Member Since:
    Oct 12, 2012
    Message Count:
    86
    Likes Received:
    27
    Trophy Points:
    50
    Eraste you saved newbies time who take hours and hours searching for the solutions :D Great and easy tutorial, I will look into this in free time, Thanks.
    Eraste likes this.
  5. Vas Origin

    Member Since:
    Jan 4, 2012
    Message Count:
    770
    Likes Received:
    175
    Trophy Points:
    500
    SDK updates may or may not have other improvements and optimizations. While there may be nothing new for banners, you don't know what else they might have changed :p
    Eraste likes this.
  6. fatos LWC Major

    Member Since:
    Apr 2, 2013
    Message Count:
    268
    Likes Received:
    73
    Trophy Points:
    200
    @Eraste Did you used one jar file for both banner and interstitial, or 2 jar files one for banner and one for interstitial
  7. Friendlyspeaking Active Member

    Member Since:
    Oct 12, 2012
    Message Count:
    86
    Likes Received:
    27
    Trophy Points:
    50
    Both the ads are included in single jar file
    Eraste likes this.
  8. Eraste Seasoned Vet

    Member Since:
    Jan 26, 2013
    Message Count:
    159
    Likes Received:
    76
    Trophy Points:
    100
    Correct when you make the SDK in the leadbolt portal it will include the different ad types you select. ap ads option includes interestinals, walls, alerts, etc.
  9. stollo770 LWC Major

    Member Since:
    Feb 2, 2012
    Message Count:
    236
    Likes Received:
    64
    Trophy Points:
    200
    I'm having an issue, I implemented everything like you instructed, but when I attempt to open the splash screen on my GS3, I get a black screen and my phone reboots. Anyone know whats wrong and how to fix it?
  10. Friendlyspeaking Active Member

    Member Since:
    Oct 12, 2012
    Message Count:
    86
    Likes Received:
    27
    Trophy Points:
    50
    ^ I was facing the similar problem and then later I came to know that I had not copied font.tff in assets folder which is defined in Splash.java
    Eraste likes this.
  11. stollo770 LWC Major

    Member Since:
    Feb 2, 2012
    Message Count:
    236
    Likes Received:
    64
    Trophy Points:
    200
    Where do you find font.ttf to copy it in?
  12. Friendlyspeaking Active Member

    Member Since:
    Oct 12, 2012
    Message Count:
    86
    Likes Received:
    27
    Trophy Points:
    50
    You can copy any .ttf font to assets > fonts and then replace the font name in Splash.java in the following line

    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/SHOWG.TTF");
  13. fatos LWC Major

    Member Since:
    Apr 2, 2013
    Message Count:
    268
    Likes Received:
    73
    Trophy Points:
    200
  14. stollo770 LWC Major

    Member Since:
    Feb 2, 2012
    Message Count:
    236
    Likes Received:
    64
    Trophy Points:
    200
    I am still unable to fix the problem. I do have a font in the assets folder titled: Merienda One.ttf. I think that should satisfy the requirement in the splash.java file but the splash screen is still crashing. Any ideas?
  15. Eraste Seasoned Vet

    Member Since:
    Jan 26, 2013
    Message Count:
    159
    Likes Received:
    76
    Trophy Points:
    100
    It may be the fonts issue. I did not include any steps for the splash screen as @Vas covered that tutorial. This tutorial assumes you already have a working splash screen!

    Here is that tutorial
    http://www.livewallpapercreator.com/community/index.php?threads/adding-a-splash-activity.412/

    The font issue is causing people problems it must be spelled correctly, capitals, lower case letters, spaces, etc. Took me 4 tries to get it to work with my font then instead of doing all that I went to my fonts folder and to all my fonts and changed their name to all lowercase an no spaces!

    So one I used before change: CHUBBY Cheeks.ttf
    After change: chubbycheeks.ttf

    This makes it a lot easier to implement in the code since you already know you everything is all lowercase you just have to match the spelling.

    Just one thing I do when building in eclipse:
    After I get a red error I locate it and try and fix it. If it gets fixed sometimes eclipse will close out the error itself sometimes not. So I will delete the error from the markers box (dont worry you wont cause any critical destruction). Then right click on the parent folder click refresh. Once eclipse refreshes the app if you fixed the error it will not show back up if you didn't it will re appear.

    I was having issues like you with eclipse failing to import the resources files of my live wallpapers after making changes to the parent folder structure. To fix this I expanded the import X at the top of the java file and made sure that the import resources line ( your package name) is there. If it was, I would do the above delete error in markers box refresh app. ( this usually fixed that error).

    Hope that helps.
  16. stollo770 LWC Major

    Member Since:
    Feb 2, 2012
    Message Count:
    236
    Likes Received:
    64
    Trophy Points:
    200
    Thanks @Eraste for the advice. @fatos sent me copies of his working splash.java and splash.xml files and I double checked what you said and got my splash page to work. It was a pain in the ass but I got it now.
  17. fatos LWC Major

    Member Since:
    Apr 2, 2013
    Message Count:
    268
    Likes Received:
    73
    Trophy Points:
    200
    @Eraste Bro can you make a tutorial for StartApp please
    Jenn and Joshua like this.
  18. Jenn Keeps coming back

    Member Since:
    Dec 8, 2013
    Message Count:
    11
    Likes Received:
    3
    Trophy Points:
    10
    I don't see the ads, is it because I added the app to leadbolt?

Share This Page