当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > 使用AngularJS 应用访问 Android 手机的图片库

使用AngularJS 应用访问 Android 手机的图片库

2019年05月29日  | 移动技术网IT编程  | 我要评论

- 4.5 kb

介绍

这篇文章来说明如何使用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 浏览器来展示获取到的一系列图片

<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>

以上所述就是本文的全部内容了,希望大家能够喜欢。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网