Android learning-(2) Build a Mobile Video Monitoring System for Android

Source: Internet
Author: User

In the previous blog post, we will continue to improve this example. We have added two new activities to display the treeactivity of the device and video channel, and browsed the imageactivity of the real-time image of a channel. treeactivity uses a listview control to display region, device, and video channel information in a hierarchical manner. It mainly involves the following knowledge points:

1. Get the JSON format data of the server response through HTTP POST

JSON format is currently widely used in Web data transmission. You can learn about JSON here. Because the server is developed in Java, there are many JSON libraries available, such as Org. JSON (no additional jar package is required. This is the built-in Android JSON-format data parsing package. However, it seems that the support for custom object classes is not very good, or it may be that I will not use it, because XML is used for web development in the past to transmit server response data), JSON-lib (powerful, but some other jar packages need to be included, it supports user-defined beans through reflection.) In the end, the override tostring () method is used for simple processing.

Code @ Override
Public String tostring ()
{
If (Enttype =   1 )
{
Return   " {\ " ID \ " : "   + ID +   " ,\ " Code \ " :\ "" + Beloneto + " \ " ,\ " Name \ " :\ "" + Hostname + " \ " } " ;
}
Else
{
Return   " {\ " ID \ " : "   + ID +   " ,\ " Code \ " :\ "" + Beloneto + " \ " ,\ " Name \ " :\ "" + Hostname
+   " \ " , \ N \ " Enttype \ " : " + Enttype + " ,\ " Type \ " : " + Dvrtype + " ,\ " IP \ " :\ ""
+ IP +   " \ " , \ N \ " Channel \ " : " + Vchlist. tostring () + " } \ N " ;
}
}

 

 

2. Customize the layout of listview adapter and list items

You can use the custom adapter class to flexibly control the processing of data presentation and related business logic, and implement a simple tree hierarchy with icon display and

 

3. Configure sharedpreferences for simple data storage

Sharedpreferences is generated as an XML file, which is similar to ASP. web. Net Development. APP under config or winform. config, which can be used to store configuration information. The function is equivalent to an INI file commonly used in Windows SDK development. In the blog Park, Terry _ dragon has a special blog post on the android project-data storage [Shared Preferences] (with the source code) to describe the use of sharedpreferences. For details, refer.

4. simple use of intent and bundle classes

Next, I will briefly introduce imageactivity, which is mainly used to obtain the video channel ID, name, and other information transmitted by treeactivity through bundle, and then enable a thread, the key to obtaining the video screen of a video at a specified interval is to generate a bitmap using urlconnection and bitmapfactorydecodestream (inputstream is), and then display it to the imageview control. The thread interacts with the UI thread through the handler. sendmessage (Message MSG) message. If the data fails to be requested for five consecutive times, a dialog box is displayed, prompting the user and closing the current imageactivity.

5. Global and localized Resources

It is easier to process this aspect on Android. One sentence is to define the corresponding resources; create a new directory under the res directory, such as values-en-rus, to display the corresponding strings on the interface when you select the region for the United States. The horizontal and vertical screens and different resolutions are also processed in a similar way, example drawable-land-160dpi

 

A good application service requires a lot of good content to provide support. I searched the internet and unfortunately did not find the devices that are open for external access. If a good application service is open to the public, such as road surveillance cameras, animal parks, and parks, you can take advantage of them to look at the road conditions and scenery. It would be better if you could look at the giant pandas.Androiddemo2.rarIn other words, the demo you downloaded cannot see the effect. It is said that some devices outside China Support HTTP or RTSP access and return JPEG images, and many devices are also open to the public, as shown in the codeproject, the C # video surveillance system for developing multi-channel IP cameras (under the effect) seems to be implemented in this mode.

As I was just getting started with Android, the electronic document eoeandroid special issue and the enterprise-level Android development that has recently been serialized in the blog Park are quite good, this allows beginners to quickly understand what Android is and smoothly enter the android development field. In terms of books, the blog Park knowledge base has been introduced, and there are also a lot of Blog content. You can refer to the simple sorting in my blog Android learning materials summary; of course, more detailed resources, if you have installed the android SDK, you can find the docs folder under its directory. This is a local document library similar to msdn provided by Google, but it only seems to be in English, but the content is full, all the API descriptions are provided ).

Related Article

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.