- How to Install Android Applications in Mobile Phone without USB Cables using Android Studio?
- Run your Android Apps
- Testing on a real device
- Stopping your apps
- Inside a Java Mobile Application, Part 1
- Getting the Demo App
- Gluon Mobile
- Edit FXML Views Using Scene Builder
- The Java Code
- The Service
- Summary
- About the Author
How to Install Android Applications in Mobile Phone without USB Cables using Android Studio?
Android Studio is the official integrated development environment for Google’s Android operating system, built on JetBrains’ IntelliJ IDEA software and designed specifically for Android app development . After successfully Setting up an Android project, and write down the necessary codes the next task is to run the application on an emulator or on a mobile phone to test whether the application is running fine or not. It’s very much easy to run the application on an emulator and to run the application on the mobile phone we have to connect our mobile phones with the PC via USB cables. Sometimes wire mesh creates a problem. To install or Debug the app wireless on the Physical Device, Android Studio provides a Plugin called Android Wifi ADB. Below is the step-by-step process to install the app on the mobile phone without USB cable.
Step 1: Open Android Studio and click on the Tools menu button as shown below.
Step 2: Now click on the SDK MANAGER as shown below.
Step 3: A new window will be open then click on Plugins as shown below in the figure.
Step 4: Again a new screen opens, then click on MarketPlace as shown below.
Step 5: After clicking on MarketPlace, type “Android Wifi ADB” in Search Box and click on the Install button and wait for download(Make sure the PC connected with internet) as shown below.
Step 6: After successful downloading click on the Restart IDE button for Restart the Android Studio as shown below.
Step 7: After Restart the Android studio, connect your device using a USB cable, and click on the Android Wifi ADB (Right Side of IDE) as shown below.
Step 8: After clicking on the Android Wifi ADB a new tab will be opened. Make sure the PC connected with your device Hotspot. Then click on the Connect button.
Step 9: In the last step disconnect your USB cable and enjoy deploying, running, and debugging the applications over Wi-Fi. Press the Play button to run the app on the device.
Note: Every time when Android Studio started, the device needs to be connected with a USB cable for the first time. After connecting your device you can remove the USB cable.
Источник
Run your Android Apps
To run an app in Android Studio, you can click the green arrow in the menu bars at the top:
Or you can click the Run menu, then select Run (we’ve cropped a few items from the menu below):
When you click on Run, you may be asked to choose a device:
As you can see, we don’t have a real device plugged in to this computer, as it says none under Connected Devices. (We’ll plug a real device in, soon.) There is an option under Available Virtual Devices, however. For us, this is Nexus 5X API 25 x86.
If you don’t see the above dialog box, then you can select a device from the dropdown list to the left of the Run button:
You can create a new Android Virtual Device by clicking the button Create New Virtual Device, or the item Open AVD Manger from the above list. When you do, you’ll see a screen like this one: (Later Versions of Android Studio will see a different screen first. Click the button in the bottom left that says Create Virtual Device.)
Click a Category on the left. We’ve selected Phone. You’ll then see a list of pre-set specs for this hardware. We’ve selected the Nexus One, which has a screen size of 3.7 inches, and a resolution of 480 by 800.
You can also create a new hardware profile by clicking the button in the bottom left. You’ll then see this screen:
But going back to the Select Hardware dialogue box, and our new Nexus One Android Virtual Device, click the Next button to see this screen:
In the image above, we’ve selected Nougat at the top. You need to select something here, otherwise you’ll get an error at the bottom of the screen and you won’t be able to click the button at the bottom to continue. If there is no item to click, select one of the download links. Android Studio will then update your software.
Again, leave these settings on their defaults. Now click the Finish button at the bottom. You will be returned to the Select Deployment Target dialogue box where you will see that your new virtual device has been added. If you don’t see this dialog box, you should see your new virtual device on the dropdown list to the left of the Run button.
Select the device and click OK on the dialogue box. Your virtual device will start up.
Running your apps on a virtual device is a lot slower than on a real device. It can take a considerable amount of time, in fact, before the apps loads!
The first thing you’ll see is a message at the bottom of Android Studio. Something like this:
Eventually, you’ll see the emulator appear:
You may see this screen for some time, depending how fast and efficient your computer is. On a slow computer, you can probably go out and do the shopping right now. By the time you get back you may, just may, see a screen like this:
This is a virtual version of the Android operating system. The final step is for your app to display. It should look like this:
And there it is — your app running on an Android Virtual Device! The text from the TextView control is Hello Android World, and is displayed on a white background. The Hello Android World in white text on a blue background at the top is the app name, and is coming from somewhere else. You’ll see how to change this in a later tutorial.
But have a look at the control strip to the right of the emulated phone. This one:
First of all, DON’T click the X in the upper right corner. This will close down the AVD, and you’ll have to start it up all over again. You can click the minimize icon just to the left of the X, though. Also, don’t click the power button, either, as this could lead to a black screen on the deice inside the emulator.
Try clicking on some of the other icons, however, especially the rotate left and right ones.
Testing on a real device
We recommend testing on a real phone or tablet. The Android Virtual Device gives a good impression of what your app will look like, but it’s not perfect. There’s no substitute for plugging in a real device into your computer via a USB micro cable.
When you do plug a real device into your computer, click Run again to see the dialogue box appear: (Newer versions if Android Studio will have the real device already selected in the dropdown to the left of the Run button so may not see this dialog box.)
The connected device is a Samsung Galaxy S6. Notice that it tells you the maximum API number that this phone supports, which is API 23. So if you’re not sure which API number your device supports, plug it in to your computer and have a look at the Connected Devices entry. (Sadly, newer version of Android Studio don’t have this information.)
Select your phone or tablet from the Connected Devices section. Click OK on the dialogue box and you should see the Hello Android World app appear on your phone/tablet.
Stopping your apps
To stop your app running and return to Android Studio, you can click the stop icon at the top:
You can also click the Run menu, then select Stop app:
A shortcut is to hold down the CTRL key on your keyboard and then press the F2 key.
Now that you have some idea of how to create and run apps, we’ll start to explore in more detail. First up is Layouts.
Источник
Inside a Java Mobile Application, Part 1
Those of you who attended the Oracle Technology Network (OTN) Java Hub or demos during a few recent Java conferences (for example, JavaOne, Devoxx, and JFokus) probably know the coffee machine that allows attendees to order a personalized coffee, the Computer Numerical Control (CNC) machine that creates user-designed badges, or any of the other «OTN Experiences.» These OTN Experiences are demonstrations of end-to-end Java projects, spanning from embedded devices, through mobile devices, and onto cloud systems.
The focus of this article is on building mobile applications that allow attendees to consume the OTN Experiences. In a follow-up article, I will talk about how the OTN Experiences are connected to the web and how they are exposed using Oracle Cloud.
There are a few mobile apps in the Apple App Store and the Google Play Store that provide the OTN Experiences. Recently, the OTN demo app was released to support the OTN Experiences at the JFokus conference. You can find it in the App Store and in the Play Store For this article, we will create a standalone Java client application that works on desktop, mobile, and embedded devices (such as the Raspberry Pi), and that provides the same user interface as the apps you could use at the conferences.
By using the Gluon Mobile IDE plugin, the Java client application can easily be installed on iOS and Android phones, without changing a single line of code. Gluon Mobile will adapt your code to the requirements of the native operating systems, and it leverages hardware-accelerated graphics using the JavaFX rendering system.
Getting the Demo App
For this article, we will use dummy back-end implementations, but as mentioned, in the next article we will replace this standalone behavior with the real cloud connection that is used to connect the mobile apps to Oracle Cloud and use the back-end functionality.
The code for this application is available in the repository at https://github.com/gluonhq/otnarticle1.git. Check out that repository using the following command:
git clone https://github.com/gluonhq/otnarticle1.git
Then run the code using this command:
Gluon Mobile
The screens you see in the application are primarily intended to run on mobile devices, so you’ll note that when running them on a desktop, the aspect ratio of the window is a similar shape. This allows developers to develop and test on a desktop system before deploying to a real mobile device for testing. However, as noted, the Gluon Mobile software stack makes it trivial to get the code onto a real mobile device. Using the following command, developers with an Apple computer who have the XCode tools installed can easily run the application on an iPhone or iPad that is connected to their system:
If you don’t have a device connected, but you want to see how the app would look on a mobile device, you can run the following command:
Developers who have the Android SDK installed can install the app on their connected Android devices by running this command:
Running the application on a mobile device is not hard, but it is beyond the scope of this article. If you experience any issues, refer to the Gluon Mobile documentation.
In the remainder of this article, I assume you are using NetBeans, IntelliJ, or Eclipse IDE and, for convenience, you already have the Gluon plugin installed. If you don’t have the Gluon plugin yet, follow these instructions.
I use NetBeans in this article, but the other IDEs follow a similar approach.
When opening the application in NetBeans, you can see that the application has a Java source section and a resource section. There are a number of iOS and Android sections, but because our application is completely cross-platform, we won’t use them.
Edit FXML Views Using Scene Builder
The OTN demo application is a Java client application, and it uses JavaFX for rendering its UI. One of the benefits of JavaFX is that the UI can be decoupled from the application’s functionality. A UI can be designed using the FXML markup language. The most popular tool for doing this is Gluon Scene Builder, which can be downloaded.
Looking in the resources/com/gluonhq/otndemo/views folder, you will see that there are four FXML files, describing the four views in the application:
Although not required, in this application, a View corresponds to a view in the mobile application. Each of those FXML files has a corresponding Presenter class that hooks the UI to the code.
The Java Code
The starting point of the application is the OtnDemo class in com.gluonhq.otndemo . This class extends MobileApplication and, thus, it can leverage some out-of-the-box functionality offered by Gluon Mobile to make the application instantly able to be deployed across iOS and Android devices.
Note: See the Javadoc while reading this article.
The OTN demo application overrides the init() and postInit() methods. In the init() method, the different views are registered. The four views that are defined in the FXML files and are controlled by the respective presenters are added to the list of views. Gluon Mobile manages the transition between the views. Once the views are registered, we can define a Layer to be used by the NavigationDrawer. The items to be shown in the NavigationDrawer are controlled by a flag called AppView.Flag.SHOW_IN_DRAWER . We add the necessary flags to the views while declaring them in the OTNView class .
The Experiences view is the default view, and it is marked as the default view using the AppView.Flag.HOME_VIEW flag. Therefore, it will be shown when the application starts. The experiences.fxml file does not contain much content. But when the Experiences view is loaded, the ExperiencesPresenter’s initialize method is called. This will create a GridPane that is shown at the center of the Experiences view. The GridPane contains two items, linked to two services that each has its own view: the CoffeeView and the BadgeView . Both the CoffeeView and the BadgeView have an FXML declaration (coffee.fxml and badge.fxml) and a controller class (CoffeePresenter and BadgePresenter) .
By inspecting the differences between the coffee code and the badge code (both the FXML files and the Presenter class) you can see that there are a number of ways to declare content in a JavaFX application. The FXML file can contain all content, and the Presenter can be empty. The other extreme is no FXML file, with the Presenter taking care of all content. The coffee and badge views both use an FXML file and a Presenter class, but the balance of content in the FXML file versus the Presenter is different.
The coffee.fxml file contains most of the view for the coffee service. Note that it contains a custom control for selecting the strength of the coffee, which was taken from the Medusa project created by Gerrit Grunwald. The badge.fxml file contains less content, and has most of its drawing code in the Presenter and in subclasses.
The FXML files have a style class defined that is used to style the nodes in the respective views via JavaFX CSS . All the styles are defined in the otn.css file.
The Service
When the user is ready to order a cup of coffee or print the badge, a request is made to a back-end service. In this first version of the OTN demo application, we don’t make a real connection to a back end. Instead, we have a Service class that mocks the connection to the back end. In a next article, we will discuss the real Service class that works with the real back-end systems.
The methods for ordering a cup of coffee and requesting a badge to be printed are expected to make a request to the back end, which returns a unique identifier corresponding to the request. Our client application creates a quick response (QR) code based on this unique identifier, and then renders the QR code. The demo hardware that was used in the OTN demo areas read this QR code, and sent it to the back end to determine the details about the requested service.
The fake Service class we are using in this article will return a random identifier, and a QR code is generated and presented to the user.
Summary
Real-world applications are often more complex than simple demos or tutorials. A combination of multiple devices, hardware, and software should be taken into account. The data flow in an end-to-end application spans between embedded and mobile devices on one end and cloud systems on the other end.
In this article, we explored how Java and JavaFX are very well positioned to be your favorite building blocks for creating Java client applications that work on mobile devices.
About the Author
Johan Vos started working with Java in 1995. He was part of the Blackdown team, porting Java to Linux. His main focus is on end-to-end Java, combining back-end systems and mobile/embedded devices. He received a Duke’s Choice Award in 2014 for his work on JavaFX on mobile devices.
In 2015, he cofounded Gluon, which allows enterprises to create mobile Java client applications leveraging their existing back-end infrastructure. Gluon received a Duke’s Choice Award in 2015. Vos is a Java Champion, a member of the BeJUG steering group and the Devoxx steering group. and he is a JCP member. He is the lead author of Pro JavaFX 8 (Apress, 2014), and he has been a speaker at numerous conferences on Java.
Источник