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.