Running on an actual device

To run your app on an actual device, you can build and copy the APK onto the device and run it from there. To do this, Android requires that the device is enabled to allow the installation of apps from unknown sources. To do this, perform the following steps:

  1. Open the Settings app on your device.
  2. Select Security.
  3. Look for and turn on the Unknown Sources option.

 

  1. You will be prompted about the danger that comes with installing apps from Unknown sources. Read carefully and click OK to confirm.
  2. That's it. You can now upload your APK and run it on the phone.
You can easily disable the Unknown Sources setting by going back to Settings | Security and turning off the option.

We can all agree that this way of running your app is not very ideal, especially for debugging. With this in mind, Android devices come with the ability to run and debug your app very easily without having to upload your app to the device. This can either be done by connecting your device via a USB cable. To do this, Android requires Developer Mode to be enabled. Follow the instructions below to enable Developer Mode:

  1. Open the Settings app on your device.
  2. Scroll down and select About phone.
  3. On the Phone status screen, scroll down and tap Build number multiple times until you see a toast that says You're now a developer!
  4. Go back to the Settings screen. You should now see a Developer options entry.
  5. Select Developer options.
  6. On the Developer options screen, turn on the switch at the top of the screen. If it's off, you'll be prompted with an Allow development settings? dialog. Click OK to confirm.
  7. Scroll down and turn on USB debugging. You'll be prompted with an Allow USB debugging? dialog. Click OK to confirm.
  8. Next, connect your device to your computer via the USB.
  9. You'll be prompted with another Allow USB debugging? dialog that has your computer's RSA key fingerprint. Check the Always allow from this computer option, and click OK to confirm.

You're now set to run your app on the device. Once again, click the Run button on the toolbar, select your device in the options shown in the Select Deployment Target dialog, and click OK:

That's it. You should now have your app showing on your device:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset