Home Plan: File sharing with HTTP for Android development

Source: Internet
Author: User
: This article mainly introduces the "home" program: File sharing with HTTP for Android development. For more information about PHP tutorials, see. Code town building: https :// Github. Com/DNA 2 Github/DNA 2mtgol/tree/master/fileShare

Recently, my mom has complained about the trouble of uploading a picture to a USB flash. I want to enable Bluetooth for others.

As a result, you need to write a program to solve the problem.

The first idea is to use the existing library. Netty and NanoHttpd are both good choices, but we also need to study how to use it, and there are a lot of tedious error processing and file read/write cache processing to do, is there a way to quickly shorten the development cycle?

As a result, the volume of calls is just compiled for Android Nginx 1.9.5, or you can directly call it!

Android Nginx 1.9.5 compilation see: the article embraces Android: compile nginx to build a mobile platform | compile the script nginx-1.9.5.sh

With nginx, everything becomes simple, as long as you can find a way for the Android App to start a separate process to run nginx, you can achieve the HTTP FileIndexService goals.

In the first step, we need to put nginx in the resource folder, and then use the code to read it and write it to the app's own data folder.

This GetResource and InputStream can be quickly combined with FileOutputStream.

Then a class nginxserveris written to start a new process using runtime.getruntime.exe c.

The result is that nginx cannot run. the adb shell goes in to view the nginx file and has no executable permission.

Yes, and socket permission denied is reported. If you do not have the network permission to open the Android AppAndroidManifest. xmlAdd a statement.

Nginx can finally be executed. when you open the browser, the error 404 is displayed.

Next, a class NginxConf is used to generate the nginx configuration file. you can enter a folder path, set the location alias in the server to this path, and enable autoindex, an HTTP file.IndexThe service is completed immediately.

Where to share the file? I used to write python-m SimpleHTTPServer in the simulated command line of Android. now I will enter a path directly to start the service!

This nginx was compiled with https and mail functions, and even websocket was supported. So the next step is to continue to expand the function of this app.

First, you can get the compiled python (click to open the link) or nodejs (click to open the link), pack the necessary libraries into zip files, and release them as needed, you can create an application server!

For example, if python is installed, prepare Django and flup. then the app runs two processes, one is python manage. py runfcgi and the other is nginx. nginx configures fcgipass, and everything is perfect!

Okay. wash your bed today. Er, it's over 11.11. it's also drunk -_-///

The above introduces the "home" plan: Android development uses HTTP for file sharing, including indexing, github, and AndroidManifest. xml content, hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.