使用AngularJS 應(yīng)用訪問 Android 手機的圖片庫
Download angularjs.zip - 4.5 KB
介紹
這篇文章來說明如何使用AngularJs調(diào)用android Apps暴露的REST APIS來訪問圖像庫.
背景
Android和IOS 有很多遠程訪問的app,但是開發(fā)者缺少遠程訪問手機特征的API.因此,myMoKit的開發(fā)是用來填補軟件解決方案的缺陷的.
使用代碼
使用代碼是很簡單的,你只要通過web URL 引用myMoKit 服務(wù),你就可以看見所有暴露的REST API了
這些在手機里面的API列表和流媒體.通過AngularJs來調(diào)用REST APIS可以很方便的使用$resource 服務(wù)。
你可以創(chuàng)建你需要的返回媒體列表的資源
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; } ]);
利用創(chuàng)建過的模塊,你可以很輕易的獲取到所有的圖片和視頻
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; }); };
你可以很方便的通過web 瀏覽器來展示獲取到的一系列圖片
<div class="alert alert-info"> <p> </p> <h4 class="alert-heading">Usage - <i>Image Gallery</i></h4> <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"><img class="img-responsive" ng-click="showImage($index)" ng-src="{{streamImageLink}}?uri={{image.contentUri}}&&id={{image.id}}&kind=1" /></li> </ul> </div>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
Javascript基礎(chǔ)_標記文字的實現(xiàn)方法
下面小編就為大家?guī)硪黄狫avascript基礎(chǔ)_標記文字的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06實例剖析AngularJS框架中數(shù)據(jù)的雙向綁定運用
這篇文章主要介紹了AngularJS框架中數(shù)據(jù)的雙向綁定運用實例,包括數(shù)據(jù)綁定中的關(guān)鍵函數(shù)與監(jiān)聽器觸發(fā)的相關(guān)講解,需要的朋友可以參考下2016-03-03AngularJS利用Controller完成URL跳轉(zhuǎn)
本文的主要內(nèi)容是介紹在AngularJS中怎樣利用Controller實現(xiàn)URL跳轉(zhuǎn),本文給出了實例代碼,簡單明了,有需要的可以參考學(xué)習(xí)。2016-08-08AngularJs bootstrap搭載前臺框架——準備工作
本文主要介紹AngularJs bootstrap搭載前臺框架,這里對Bootstrap 搭載環(huán)境,及注意事項做了講解,有需要的小伙伴可以參考下2016-09-09AngularJS入門(用ng-repeat指令實現(xiàn)循環(huán)輸出
這篇文章主要介紹了AngularJS入門(用ng-repeat指令實現(xiàn)循環(huán)輸出,需要的朋友可以參考下2016-05-05AngularJS實現(xiàn)的根據(jù)數(shù)量與單價計算總價功能示例
這篇文章主要介紹了AngularJS實現(xiàn)的根據(jù)數(shù)量與單價計算總價功能,涉及AngularJS事件響應(yīng)與數(shù)值運算相關(guān)操作技巧,需要的朋友可以參考下2017-12-12