使用AngularJS 應(yīng)用訪問 Android 手機(jī)的圖片庫
Download angularjs.zip - 4.5 KB
介紹
這篇文章來說明如何使用AngularJs調(diào)用android Apps暴露的REST APIS來訪問圖像庫.
背景
Android和IOS 有很多遠(yuǎn)程訪問的app,但是開發(fā)者缺少遠(yuǎn)程訪問手機(jī)特征的API.因此,myMoKit的開發(fā)是用來填補(bǔ)軟件解決方案的缺陷的.
使用代碼
使用代碼是很簡(jiǎn)單的,你只要通過web URL 引用myMoKit 服務(wù),你就可以看見所有暴露的REST API了


這些在手機(jī)里面的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>

以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
相關(guān)文章
Javascript基礎(chǔ)_標(biāo)記文字的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狫avascript基礎(chǔ)_標(biāo)記文字的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06
基于angular實(shí)現(xiàn)樹形二級(jí)表格
這篇文章主要介紹了angular手寫樹形二級(jí)表格的完整代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-10-10
Angular實(shí)現(xiàn)form自動(dòng)布局
這篇文章主要介紹了Angular實(shí)現(xiàn)form自動(dòng)布局的相關(guān)資料,以代碼片段的形式分析了Angular實(shí)現(xiàn)form自動(dòng)布局的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-01-01
實(shí)例剖析AngularJS框架中數(shù)據(jù)的雙向綁定運(yùn)用
這篇文章主要介紹了AngularJS框架中數(shù)據(jù)的雙向綁定運(yùn)用實(shí)例,包括數(shù)據(jù)綁定中的關(guān)鍵函數(shù)與監(jiān)聽器觸發(fā)的相關(guān)講解,需要的朋友可以參考下2016-03-03
AngularJS利用Controller完成URL跳轉(zhuǎn)
本文的主要內(nèi)容是介紹在AngularJS中怎樣利用Controller實(shí)現(xiàn)URL跳轉(zhuǎn),本文給出了實(shí)例代碼,簡(jiǎn)單明了,有需要的可以參考學(xué)習(xí)。2016-08-08
AngularJs bootstrap搭載前臺(tái)框架——準(zhǔn)備工作
本文主要介紹AngularJs bootstrap搭載前臺(tái)框架,這里對(duì)Bootstrap 搭載環(huán)境,及注意事項(xiàng)做了講解,有需要的小伙伴可以參考下2016-09-09
AngularJS入門(用ng-repeat指令實(shí)現(xiàn)循環(huán)輸出
這篇文章主要介紹了AngularJS入門(用ng-repeat指令實(shí)現(xiàn)循環(huán)輸出,需要的朋友可以參考下2016-05-05
AngularJS實(shí)現(xiàn)的根據(jù)數(shù)量與單價(jià)計(jì)算總價(jià)功能示例
這篇文章主要介紹了AngularJS實(shí)現(xiàn)的根據(jù)數(shù)量與單價(jià)計(jì)算總價(jià)功能,涉及AngularJS事件響應(yīng)與數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-12-12

