android.html 14 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>android</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/android.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>android</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#changing-the-name-of-your-apk-application">Changing the Name of Your APK/Application:</a></li><li><a href="#changing-the-apk-icon">Changing the APK Icon:</a></li><li><a href="#adding-a-splash-screen-to-your-app">Adding a Splash Screen to your app:</a></li><li><a href="#compile-the-jar-file-for-use-with-your-project">Compile the jar file for use with your project:</a></li><li><a href="#adding-play-games-services-to-your-project">Adding Play Games Services to Your Project:</a></li><li><a href="#adding-admob-support-to-your-project">Adding AdMob Support to Your Project:</a></li><li><a href="#communication-between-your-application-main-activity">Communication Between your Application &amp; Main Activity:</a></li><li><a href="#changing-the-package-name-after-project-creation">Changing the Package Name After Project Creation:</a></li></ul></div></div><div id="content"><div class="sect1"><h2 id="changing-the-name-of-your-apk-application">Changing the Name of Your APK/Application:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Open your project’s properties and navigate to Application</p></li><li><p>Update the title</p></li></ol></div>
  4. <div class="paragraph"><p>This has no real effect, however it keeps continuity throughout your app. Actually, this likely renamed the window created to display your app. So, now go change the actual name of your APK:</p></div>
  5. <div class="olist arabic"><ol class="arabic"><li><p>Select <code>File View</code> in the left pane of the SDK.</p></li><li><p>Navigate to the <code>mobile/res/values</code> directory and open the <code>strings.xml</code> file.</p></li><li><p>There should be a string tag with the following key pair: name="app_name".</p></li><li><p>Replace <code>MyGame</code> with your app&#8217;s name and save the file.</p></li><li><p>In <code>File view</code>, navigate to nbproject and open the <code>project.properties</code> file.</p></li><li><p>Edit the value of <code>application.title</code> to reflect your game&#8217;s name (unless step 1/2 above altered this for you).</p></li></ol></div></div></div>
  6. <div class="sect1"><h2 id="changing-the-apk-icon">Changing the APK Icon:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Under the <code>File view</code> of your project navigate to <code>mobile/res</code> and add a <code>drawable</code> folder if one does not exist.</p></li><li><p>Add your icon file (png).</p></li><li><p>Open the Android Manifest file and add the following to your application tag:</p><div class="paragraph"><p><code>android:icon="@drawable/&lt;ICON FILE NAME WITHOUT EXTENSION&gt;"</code></p></div></li><li><p>If you would like multiple size icons, add the following folders:</p><div class="literalblock"><div class="content"><pre>drawable-hdpi (should contain the icon named the same at 72×72 pixels)\\
  7. drawable-ldpi (should contain the icon named the same at 36×36 pixels)\\
  8. drawable-mdpi (should contain the icon named the same at 48×48 pixels)\\
  9. drawable-xhdpi (should contain the icon named the same at 96×96 pixels)\\</pre></div></div></li></ol></div></div></div>
  10. <div class="sect1"><h2 id="adding-a-splash-screen-to-your-app">Adding a Splash Screen to your app:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Open <code>Android Main Activity</code>, either through the <code>Important Files</code> list in <code>Project view</code> or in the <code>File view</code> under <code>mobile/src/&lt;package name&gt;</code> directory.</p></li><li><p>Add the following line to the <code>MainActivity</code> method:</p><div class="paragraph"><p><code>splashPicID = R.drawable.&lt;IMAGE NAME WITHOUT EXTENSION&gt;;</code></p></div></li><li><p>Add the image to the <code>mobile\res\drawable</code> directory.</p></li></ol></div>
  11. <div class="paragraph"><p>Compiling Google Play Services and Adding it to Your Project:</p></div>
  12. <div class="paragraph"><p>First get the api:</p></div>
  13. <div class="olist arabic"><ol class="arabic"><li><p>Download the google play services add-on through the SDK Manager under Extras (named Google Play services).</p></li><li><p>Copy the directory from where you downloaded it to another location (like JME Projects Folder).</p></li></ol></div></div></div>
  14. <div class="sect1"><h2 id="compile-the-jar-file-for-use-with-your-project">Compile the jar file for use with your project:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>In the directory you copied, there is an android project file.</p></li><li><p>In JME&#8217;s IDE, open this project</p></li><li><p>In the General section of the project properties, there is a list of potential Android target platforms. Select the one you are using for your project by clicking on the list (this is not intuitive at all, as the list looks like nothing more than info… not selectable items).</p></li><li><p>Under the Library section, click the checkbox that is labeled:</p><div class="ulist checklist"><ul class="checklist"><li><p><i class="fa fa-check-square-o"></i> Is Library</p></li></ul></div></li><li><p>Click <b class="button">Ok</b> and then Clean &amp; Build this project.</p></li></ol></div>
  15. <div class="paragraph"><p>This will compile the play services all proper like so you can add it to your project. Now, for that step:</p></div>
  16. <div class="olist arabic"><ol class="arabic"><li><p>Open your project’s properties.</p></li><li><p>In the Libraries section, click the <b class="button">Add JAR/folder</b> button.</p></li><li><p>Find and add the jar you compiled above. This can be found in:</p><div class="paragraph"><p><code>&lt;COPIED DIR&gt;\libproject\google-play-services_lib\libs\google-play-services.jar</code></p></div></li><li><p>Modify your Android Manifest by adding the following tags under application:</p><div class="paragraph"><p><code>&lt;meta-data android:name="com.google.android.gms.games.APP_ID"
  17. android:value="@string/app_id" /&gt;
  18. &lt;meta-data android:name="com.google.android.gms.version"
  19. android:value="@integer/google_play_services_version"/&gt;</code></p></div></li><li><p>Add the following tag to your mobile/res/values/integers.xml file (create it if it doesn’t exist):</p><div class="paragraph"><p><code>&lt;integer name="google_play_services_version"&gt;4323000&lt;/integer&gt;</code></p></div></li><li><p>Clean &amp; Build your project</p></li></ol></div></div></div>
  20. <div class="sect1"><h2 id="adding-play-games-services-to-your-project">Adding Play Games Services to Your Project:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Download the project from:</p><div class="paragraph"><p><a href="https://github.com/playgameservices/android-samples">https://github.com/playgameservices/android-samples</a></p></div></li><li><p>In the following directory, you find java files you will need to add to your project:</p><div class="literalblock"><div class="content"><pre>&lt;DOWNLOAD DIR&gt;\android-samples-master\BasicSamples\libraries\BaseGameUtils\src\main\java\com\google\example\games\basegameutils\\
  21. Grab GameHelper.java and GameHelperUtil.java and add them to the directory you projects Main Activity is in\\</pre></div></div></li><li><p>In the following directory, you find a resource file you will need to add to your project:</p><div class="literalblock"><div class="content"><pre>&lt;DOWNLOAD DIR&gt;\android-samples-master\BasicSamples\libraries\BaseGameUtils\src\main\res\values\\
  22. Grab the gamehelper_strings.xml into your mobile/res/values folder\\</pre></div></div></li><li><p>Add the following jar from the Adroid SDK folder to your project as a library:</p><div class="literalblock"><div class="content"><pre>&lt;ANDROID SDK INSTALL DIR&gt;\adt-bundle-windows-x86_64-20131030\sdk\extras\android\support\v4\android-support-v4.jar\\</pre></div></div>
  23. <div class="paragraph"><p>And this is the basics for setting this up.</p></div></li></ol></div></div></div>
  24. <div class="sect1"><h2 id="adding-admob-support-to-your-project">Adding AdMob Support to Your Project:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Open your Android Manifest and add the following tag update the application tag:</p><div class="paragraph"><p><code>&lt;activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/&gt;</code></p></div></li><li><p>After the application tag, add the following tags:</p><div class="paragraph"><p><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;<br>
  25. &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;</code></p></div></li><li><p>In the onCreate method of your Main Activity, add the following snippet (configure however you like):</p><div class="literalblock"><div class="content"><pre>adView = new AdView(this);
  26. adView.setAdSize(AdSize.FULL_BANNER);
  27. adView.setAdUnitId("&lt;WHATEVER AD UNIT ID YOU ARE ASSIGNED THROUGH THE GOOGLE DEV CONSOLE&gt;");
  28. adView.buildLayer();
  29. LinearLayout ll = new LinearLayout(this);
  30. ll.setGravity(Gravity.BOTTOM);
  31. ll.addView(adView);
  32. addContentView(ll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));</pre></div></div></li></ol></div></div></div>
  33. <div class="sect1"><h2 id="communication-between-your-application-main-activity">Communication Between your Application &amp; Main Activity:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Create an interface named something along the lines of <code>JmeToHarness.java</code>.</p></li><li><p>Open your <code>Android Main Activity</code> and implement this interface.</p></li><li><p>In <code>Main.java</code> of your Application, add the following:</p><div class="literalblock"><div class="content"><pre> JmeToHarness harness;
  34. public JmeToHarness getHarness() {
  35. return this.harness;
  36. }
  37. public void setHarnessListener(JmeToHarness harness) {
  38. this.harness = harness;
  39. }</pre></div></div></li><li><p>Add the following snippet to the onCreate method of your Android Main Activity:</p><div class="literalblock"><div class="content"><pre>if (app != null)
  40. ((Main)app).setHarnessListener(this);</pre></div></div></li><li><p>Add error handling if you want it.</p></li></ol></div>
  41. <div class="paragraph"><p>This bit is ultra useful for calling AdMob changes and Play Games methods (like updating achievements, leader boards, etc, etc)</p></div>
  42. <div class="paragraph"><p>EDIT: Keep this as generic as you possibly can as it should plug &amp; play with iOS &amp; Applets if you keep that in mind. Google Play Services/Play Games Services works for all of the above… soooo… anyways.</p></div></div></div>
  43. <div class="sect1"><h2 id="changing-the-package-name-after-project-creation">Changing the Package Name After Project Creation:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Open the project properties of your Application</p></li><li><p>Navigate to <code><span class="menuseq"><span class="menu">Application</span>&#160;&#9656; <span class="menuitem">Android</span></span></code> and edit the package name.</p></li></ol></div>
  44. <div class="paragraph"><p>This does absolutely nothing, but help with consistency.</p></div>
  45. <div class="paragraph"><p>So, to actually change the package name, you will want to:</p></div>
  46. <div class="olist arabic"><ol class="arabic"><li><p>Open the <code>Android Manifest</code></p></li><li><p>Edit the manifest tag key pair: <code>package="&lt;THE NEW PACKAGE NAME&gt;"</code></p></li><li><p>In <code>File view</code>, navigate to nbproject and open the <code>project.properties</code> file.</p></li><li><p>Edit the value of <code>mobile.android.package</code>.</p></li></ol></div>
  47. <div class="paragraph"><p>Take a moment or 4 to navigate through the directory structure in file view and remove any artifacts left from the previous package name build. Alternately, you can run <code>Clean</code> on the project prior to updating the package name.</p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  48. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  49. indexName: 'jmonkeyengine',
  50. inputSelector: '#doc-search',
  51. debug: false // Set debug to true if you want to inspect the dropdown
  52. });</script></body></html>