设为首页 加入收藏

TOP

AngularJS 应用访问 Android 手机的照片库
2015-04-07 15:30:00 来源: 作者: 【 】 浏览:44
Tags:AngularJS 应用 访问 Android 手机 照片库

相关下载:


------------------------------------------分割线------------------------------------------


------------------------------------------分割线------------------------------------------


介绍


这篇文章来说明如何使用AngularJs调用android Apps暴露的REST APIS来访问图像库.


Android和IOS 有很多远程访问的app,但是开发者缺少远程访问手机特征的API.因此,myMoKit的开发是用来填补软件解决方案的缺陷的.


使用代码是很简单的,你只要通过web URL 引用myMoKit 服务,你就可以看见所有暴露的REST API了


这些在手机里面的API列表和流媒体.通过AngularJs来调用REST APIS可以很方便的使用$resource 服务。



你可以创建你需要的返回媒体列表的资源


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;
?
? ? } ]);


利用创建过的模块,你可以很轻易的获取到所有的图片和视频


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 浏览器来展示获取到的一系列图片




?

Usage - Image Gallery


?


?
?

    ? ?




一些AngularJS相关文章链接


希望你喜欢,并分享我的工作~带你走近AngularJS系列


英文原文:AngularJS App to access Android Phone Gallery


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇在Linux上使用Python和Flask创建.. 下一篇Maven项目的目录结构

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: