Use AngularJS to access the image library of the Android mobile phone

Source: Internet
Author: User

Use AngularJS to access the image library of the Android mobile phone
This article mainly introduces how to use AngularJS applications to access the image library of Android mobile phones. For more information, see

 

 

Download angularjs.zip-4.5 KB

Introduction

This article explains how to use AngularJs to call the rest apis exposed by android Apps to access the image library.

Background

Android and IOS have a lot of apps for remote access, but developers lack APIs for remote access to mobile phone features. Therefore, myMoKit is developed to fill in the defects of software solutions.

Use Code

The code is very simple. You only need to reference the myMoKit service through the web URL, you can see all the exposed REST APIs.

These APIS and streaming media in the mobile phone. Calling rest apis through AngularJs makes it easy to use the $ resource Service.

You can create resources that you need to return to the media list.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

Angular. module ('resources. media ', ['ngresource']);

Angular. module ('resources. media '). factory (

'Media ',

[

'$ RootScope ',

'$ Resource ',

'$ Location ',

'$ Http ',

Function ($ rootScope, $ resource, $ location, $ http ){

Var mediaServices = {};

MediaServices. getAllMedia = function (media ){

Var path = $ rootScope. host + '/services/api/media/' + media;

Return $ resource (path ,{},

{

Get :{

Method: 'get ',

IsArray: false

}

});

};

Return mediaServices;

 

}]);

Using the created modules, you can easily obtain all images and videos.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

Var getAllImages = function (){

Media. getAllMedia ('image'). get (). $ promise. then (

Function success (resp, headers ){

$ Scope. allImages = resp;

$ Scope. images = $ scope. allImages. images;

}, Function err (httpResponse ){

$ Scope. errorMsg = httpResponse. status;

});

};

 

Var getAllVideos = function (){

Media. getAllMedia ('video'). get (). $ promise. then (

Function success (resp, headers ){

$ Scope. allVideos = resp;

$ Scope. videos = $ scope. allVideos. videos;

}, Function err (httpResponse ){

$ Scope. errorMsg = httpResponse. status;

});

};


You can easily use a web browser to display a series of obtained images.

?

1

2

3

4

5

6

7

8

9

10

11

12

<Div class = "alert-info">

<P> </p>

 

<H4 class = "alert-heading"> Usage-<I> Image Gallery </I>

 

<P> </p>

 

 

<Ul class = "row">

<Li class = "col-lg-2 col-md-2 col-sm-3 col-xs-4" ng-repeat = "image in images" style = "margin-bottom: 25px "> </li>

</Ul>

</Div>

The above is all the content of this article. I hope you will like it.

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.