In this Post I am will give an instructional exercise that shows setting up an Android improvement condition in NetBeans and really making a snappy application to pass on how simple it can be previously it’s set up and running on your gadget or an Android Virtual Machine.
Step one – Downloading files needed
Firstly (if you haven’t already), download the android SDK. This is necessary to be able to create a working android application in NetBeans.Best Sellers
Step two – Creating Android Virtual Machine
Note: If you are planning on using your own android device to test the application you create then skip this step.
Go to the SDK, and afterward open the AVD Manager executable. Here you should see a void rundown of Virtual Devices, to include a single tick “make” and after that fill in the cases in the discourse with what you need your testing gadget to be (regardless of whether it be low spec or high it might at present slack contingent upon your framework details). Once you’ve done this you can begin your new Android Virtual Device.
Step Three-Installing SDK Manager Files
Explore back to the SDK organizer and access the SDK Manager, here you pick what bundles you need to download for android. I would suggest choosing all the android rendition bundles (or simply the adaptation of your android gadget or AVD for testing). Tap on Tools envelope box (so it chooses every single inward document), and introduce these too.
Note: This will be a big download if you’re not careful, so you could only download the relevant files to your mobile device.
Step Four – Adding an update centre
On NetBeans, navigate to Tools, Plugins and then Settings. From here you need to add a new update centre. Give a name (preferably Android so it’s easily identifiable) and then use the URL shown below
After adding this navigate to “Available Plugins”, and search “Android”, when this appears install it.Then after this go to “Tools” again, then “Settings” and “Miscellaneous” then on the first (android) tab, give an SDK location.
Step Five – Creating the project
Now you are ready to create a project so you can start some Android Java programming. Navigate to the file tab on the toolbar, and click “New Project”. Then you will need to click Android in the Categories list, and Android Project then Next.
Now you will have to configure the project correctly, so give your project a sensible name (I’ve called mine “TechBlogTest”!), and now choose a location for your project.
The target platform is what we installed earlier on the SDK Manager, choose an applicable platform, for example: “Android 5.0.1”.
Now you’ve got your project configured you will want to go to the source code (this is in Source Packages and then whatever you called your package).
Then click through to your Main Activity class, it may say you have an error in your code but just clean and build the project and it should go
Here is your main class, this is the code that is deployed when you run the application.
Step Seven – Deploying to mobile or Android Virtual Machine.
In the event that you are utilizing an Android Virtual Machine then when you click run it should think of your gadget (if not effectively open), or simply raise a clear “Fundamental Activity” named application.
However, in the event that you need to utilize your own portable then you will need to get to settings on your android gadget and go to “About gadget”, at that point tap the Build number rundown thing until the point that the warning shows up expressing that you are currently a designer.
Presently when you are on settings, you should see the “Engineer Options” menu, on the off chance that you click this there are a huge number of choices accessible for you to play around with amid advancement and testing; the one we require is USB troubleshooting. When USB troubleshooting is chosen and on you should connect your telephone to the PC, sit tight for it to show up and you are currently set to convey to your cell phone!
Run the application and sit tight for the application to fly up on your telephone (it ought to be clear with the default name and portrayal). In the event that an exchange shows up requesting that whether you need keep running in a Virtual Device or the USB Android gadget, select the appropriate one and proceed.
Step Eight – Using XML in Android.
If you navigate to “Resources”, “layout” and then “main” you need to edit this to add elements to the User Interface (UI).You will want to add the xml code shown below in the “LinearLayout” tag in your main.
The “@+id” tag allows us to create a new id that we can access from the code, we call it “sound button” in this instance but you can call it whatever you like. The “@string” tag in the text part of the button is the text displayed on the UI. To do this you need to access the strings xml at “Resources”, “values” and then ”strings”, the name is what we access from the main xml, and the text in black is what will be displayed on the UI.
Note: Any text that you will display on the UI from the XMl file will need the text to be in the strings XML file like shown above.
Step Nine – Adding action listener to the Main Activity.
You will need to create a button click listener in the “on Create” function, to do so you need to add a button variable and find the button by using the id tag we set earlier.
The “button” variable is your button from the XML, this will be used to check if it has been clicked and if it has to go into the “on Click” function that will trigger a sound or whatever you want for this example.
Note: Once you add this code you will get many errors, this is because you need to import some things. Click on the lightbulbs that will appear, and add the imports for the red error underlined parts shown.
Step 10 – Adding sounds on button click.
You will need to create a media player member variable so you can give this a sound upon the pressing of the button, to declare this variable in the “Main Activity” public class, add the following code:
This variable can now be accessed in the main code to add a sound, you will need any wav file for this (could be anything as long as it is a wav file type).
Now you need to add a new file to resources, right click on “Resources” go “new->folder” and call this “raw”. Drag and drop the wav file into this.
Create the sound, referencing from the resources (change example_sound to whatever wav you dragged and dropped into raw). You will need to add the line of code below in the “onCreate” function so that we know what the sound is.
And now in the “onClick” function add “mp.start();” as this starts the sound when this button is clicked. You can also call “mp.stop();” when you want to stop a sound.These are useful if you want to create a game with dynamic sounds that start and stop at different points in time.
Step 11 – Finishing up the application
Since the greater part of the code is set up you should change the name of the application or possibly the application symbol. You will need to go to the “Assets”, “values” at that point” strings” and change the “app_name” string to whatever you need. Presently get to the “Android show document” in the “Imperative records” organizer, at that point you will find in the movement tag “android: name”, change this to the strings name “app_name”.
On the off chance that you need to change the symbol of the application, this is underneath the application tag in the show document; you should drag a PNG picture to any of the “drawable” records in Resources, the distinctive esteems suffixed are quality (include pertinent pictures for various sizes in the event that you need). Presently you’ve done this, change the tag underneath “android: symbol” to the name of the picture you’ve quite recently embedded into the “drawable” envelopes.
Presently you have a working custom Android application that you can completely alter and change now you have the nuts and bolts in a NetBeans venture.
For more relevant information & queries…pls click on www.4blocksinc.com