- Running Apps on Your Device
- Smooth loading animations in Android
- The UX problem
- Two false starts
- A promising solution
- Default to Open
- How to Install APK on Android
- Have an Android app not on Google Play? Install it from its APK
- What to Know
- Allow Unknown Apps on Android
- Install an Android File Manager
- Download the APK Installer From Your Android
- Transfer the APK Installer via USB
- Advanced: Run APK Installer With Minimal ADB and Fastboot
- What Is an APK?
- Why Use an APK?
- Finding APK Installers
Running Apps on Your Device
When building an Android app, it’s important that you always test your application on a real device in addition to emulators. This page describes how to set up your development environment and Android-powered device for testing and debugging on the device.
If you want an ideal SIM-unlocked phone to test on, then you might consider a Pixel phone.
Plug in your device to your computer with a USB cable. If you’re developing on Windows, you might need to install this universal ADB USB driver or find your specific USB driver for your device.
The next step is to enable USB debugging so your phone can interact with your computer in a developer mode.
The following steps are needed:
- (Windows Only) Install this ADB Driver
- Plug-in your Android Device to Computer via USB
- Open the «Settings» App on the Device
- Scroll down to bottom to find «About phone» item
- Scroll down to bottom to find «Build number» section
- Tap on «Build Number» 7 times in quick succession
- You should see the message «You are now a developer!»
- Go back to main «Settings» page
- Scroll down bottom to find «Developer options» item
- Turn on «USB Debugging» switch and hit «OK»
- Unplug and re-plug the device
- Dialog appears «Allow USB Debugging?»
- Check «Always allow from this computer» and then hit «OK»
Watch this video tutorial for a visual guide to getting USB debugging enabled.
Now, we can launch apps from Android Studio onto our device:
- Select one of your projects and click «Run» from the toolbar.
- In the «Choose Device» window that appears, select the «Choose a running device» radio button, select the device, and click OK.
Once Gradle finishes building, Android Studio should install the app on your connected device and start it.
Not seeing your device in the «Choose Device» window? Try the following:
- Unplug your device from the USB port on the computer
- Restart the device by powering off and back on
- Verify that Settings => Developer options => USB Debugging is enabled
- Quit and re-launch Android Studio
- Force restart ADB from the «Android Device Monitor»
- Plug your device back into the USB port on the computer
- Unlock the device and press «OK» on any dialog displayed
Now the phone should work as a debugging device as expected!
Still Not Working?
If after plugging the device into the computer and you don’t see any message about authorizing the device, then you may need to purchase another USB cable. Not all USB cables are enabled for data transfer. If there’s a chance that your cable may be a charging only cable, you can purchase a USB-C cable for Pixel or the micro-USB cable for Nexus 6 and prior.
Источник
Smooth loading animations in Android
RxJava can seem removed from the world of user experience. It’s easy to think of it as a tool for back-end only. Today we’ll look at a real front-end problem, how to apply marble diagrams to solve it, and how to use Kotlin to clean up the solution. We’ll also look at the difference between throttling and debouncing, and some lesser-know overloads of debounce and delay .
The UX problem
We’re often trying to avoid flicker and flashes on Android apps. One common scenario where this can occur is loading from an API call. We want to show a loading animation if the API call takes too long. But if the API call is almost instantaneous, we don’t want to flicker between a quick loading animation and the content of the page.
There are some existing tools for getting around this, for example the ContentLoadingProgressBar in the Android SDK. Of course, top-tier apps have placeholder views instead of progress bars:
These types of views are best composed in a RecyclerView. The RecyclerView will manage the scheduling of UI updates to avoid the jarring effect when a View is suddenly inserted into a ViewGroup. But this is often not enough to prevent a flicker, flash, or jarring animation:
Since we’re just putting a data into a RecyclerView.Adapter , how do we avoid the flicker of a loading animation for a quick load?
The current feature is a suburb picker to specify pickup location for users selling items on Trade Me.
In the implementation, the Fragments are humble views that simply subscribe to streams of content when they come into focus. The Activity publishes the content for the display, with the Fragment simply subscribing to updates in content. Note the publisher here could also be a ViewModel or a controller Fragment.
Since the published content is received as a reactive streams, we should easily be able to find a combinator on Observable to remove the flicker.
Two false starts
Observable#throttleLast seems like a good candidate. Looking at the above marble diagram, imagine that:
- the red marble represents our “still loading” state
- the orange marble represents our loaded state
- the other colored marbles represent UI updates from user interactions
Intervals of the delay parameter are represented by the clocks on the diagram.
The marbles at the top represent a stream of events as input into the box, with time flowing from left to right. The box is a function on Observable and the marbles at the bottom represent the resultant stream of events after the function has been applied.
Since the red marble (loading) was emitted before the tick of the clock, it is ignored and only the orange marble (loaded) is emitted.This is similar to the result we want: if the loading state is too quick we want it to be dropped and invisible to the user.
However, throttleLast is not quite right for the subsequent events. Imagine that the yellow and green marbles are events triggered by a user interaction e.g., clicking one of the items in the RecyclerView .
The yellow marble is ignored, which may be desirable since it occurred quite quickly before the green one. But the emission of the green marble is delayed until another tick of the clock. This is not what we want — we would prefer the green marble to be emitted immediately so that there is no delay between the user interaction (the click) and the result on screen (the change in the UI).
Since we’ve ruled out Observable#throttleLast , why not look at Observable#debounce ? This certainly sounds more like what we want to achieve. The first overload has a signature that looks like this:
The marble diagram looks like this:
Just from the diagram, we can see that the marbles are only being emitted after the tick of the clock. This is the same mismatch of use case we found for throttleLast .
What we really want is something that can debounce only in the case of loading, and leaves the other marbles to fall immediately.
A promising solution
Turns out there is an overload of debounce that achieves just this:
The combinator in the box shows three arrows of lengths 1, 2, and 3 for f(1) , f(2) , and f(3) . These represent three different debounce intervals. This shows we can achieve debouncing determined by a function, closer to what we want.
A concrete example is found in this Stack Overflow answer by Lawrence Kesteloot:
This clearly explains the parameter debounceSelector : it’s a function that takes as input T and outputs an Observable representing a debounce interval.
Now we can do this:
We can use the Extract Method refactor and type aliases to make this a little bit cleaner:
If it’s something we might use in more than a few places in the app, we could easily write an extension method to take the abstraction further:
Then we can use it like this:
We can write unit tests against the extension function using the TestScheduler since it allows fast-forwarding of time to see which elements have been emitted. We can also use an overload of Observable#delay to prepare the test data. It’s very similar to the overload of Observable#debounce we were using earlier:
The complete set of unit tests is below. Note how we can model our use cases exactly:
The final feature without flicker:
David Rawson is an Android Developer at Trade Me. You can find him on Stack Overflow here.
Default to Open
Life lives here. Stories about how we’re building Trade Me.
Источник
How to Install APK on Android
Have an Android app not on Google Play? Install it from its APK
What to Know
- Allow Chrome to install unknown apps by going to Settings >Apps >Menu >Special access >Install unknown apps.
- Install a file manager (such as Cx File Explorer or File Manager) so that you can find the APK file after you download it to your phone.
- Download an APK file and open it to install it. Alternatively, transfer the APK Installer from your computer using USB.
If you want to use an app from outside of the Google Play Store, you can install the app’s APK file. This article explains how to install APKs on Android 7 or later.
Allow Unknown Apps on Android
Before you can download APK files using Chrome or any other browser, you must first allow unknown apps:
Go to your device settings and tap Apps & Notifications (or Apps in older versions of Android).
Tap the three dots in the upper-right corner.
Tap Special access.
Tap Install unknown apps.
Tap Chrome (or whichever web browser you use)
Move Allow from this source to the On position.
Install an Android File Manager
Now that you’ve configured your phone to let you install unknown apps, you’ll need a way to find the application file (APK file) on your phone so that you can run it.
Android phones typically come with a file manager app you can use, but if you don’t have one, search for one on Google Play. Some of the best options include Cx File Explorer and File Manager.
Download the APK Installer From Your Android
The easiest way to install an APK file on your Android is to download the file using the default browser, Chrome.
Find a website offering the Android app and tap the link to download the APK file. Accept any pop-ups, including “This type of file can harm your device.”
Only download APK files from reputable sources. A quick Google search can often let you know if an app (or company that makes the app) has a questionable reputation.
If your phone’s web browser doesn’t give you the option to open the file after downloading, open your file explorer app, go to the Downloads folder on your device, then tap the APK file.
Allow the app any required permissions it asks for. Then, at the bottom of the installer window, tap Install.
Now you’ll see the app available in your list of installed apps.
Transfer the APK Installer via USB
If you don’t have internet access on your phone, or for any other reason you can’t use a browser to download the file, you can still install apps from your computer. Using your computer web browser, download the APK file just like described above. Once it’s downloaded, connect to your Android phone and transfer the file.
If you’ve never connected your Android to your computer, enable USB Debugging. You can then plug your phone into your computer with a USB cable, and it’ll mount the phone like it would a memory stick.
Once your phone is connected to your computer, it shows up as another drive in your computer’s File Explorer. Move the APK file you downloaded from the app website to the /sdcard/download folder on your phone.
Once the file is transferred, use the file explorer app on your phone as described in the previous section to tap the APK file and install the app.
If you don’t have a USB cable, another solution is to install WiFi FTP Server from Google Play. Then, use an FTP client on your computer (like FileZilla) to transfer the APK file from your computer to the /sdcard/download folder on your phone. However, this is an advanced option and requires an understanding of how to use FTP files.
Advanced: Run APK Installer With Minimal ADB and Fastboot
If the APK installer isn’t running when you tap it, there’s an advanced solution that might work. You can install the APK file on your Android from your computer using a tool called Minimal ADB and Fastboot.
Connect your phone via USB and enable USB Debugging.
Download and install the latest version of Minimal ADB and Fastboot on your computer.
Run the tool, and a command window opens. With your phone connected to your computer with the USB cable, type the command adb devices.
If the tool detects your phone, an ID for the device appears under List of devices attached. Now you’re ready to transfer the APK file.
Using Windows File Explorer, find the downloaded APK file on your computer.
Right-click the file and select Copy.
Using Windows File Explorer, navigate to the Minimal ADB and Fasbtoot folder (typically c:\Program Files (x86)\Minimal ADB and Fastboot\).
Paste the APK file into that folder.
Rename the APK file to something short so that it’s easy to type as a command.
Back in the same command window you had open before, type the command adb install app name (replace with the name of your APK file).
When you see the word Success, the app is installed on your phone.
What Is an APK?
An APK (Android Package Kit) is a type of file that installs an application for Android. It’s just like an executable (EXE) file for Windows or a package installer (PKG) for Mac.
If you’ve ever installed an Android application from the Google Play store, then you’ve used an APK file without realizing it. When you tap the Install button, Google Play automates the process of transferring the APK file to your phone and running it for you.
Why Use an APK?
If the Android app you want to install isn’t available on Google Play, you can download the APK file from the web and install it manually.
Finding APK Installers
There are many websites where you can find non-Google Play apps to install. Three of the most popular are APK Pure, Reddit’s APK Directory, and APK Mirror.
Источник