{"id":3112,"date":"2020-08-13T06:24:19","date_gmt":"2020-08-13T06:24:19","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=3112"},"modified":"2023-02-20T12:53:55","modified_gmt":"2023-02-20T12:53:55","slug":"getting-all-media-from-mobile-gallery-in-react-native","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/","title":{"rendered":"Getting all media from Mobile gallery in React-native"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>React native provides many packages to access the gallery and camera. To get all types of media from <a href=\"https:\/\/studysection.com\/blog\/best-practices-in-mobile-application-development\/\">mobile<\/a>, react-native provides the cameraRoll. It is a native module of react-native which provides access to the local camera roll or photo library.<\/p>\n<h3>Installation using npm:<\/h3>\n<p><em>$ npm install @react-native-community\/cameraroll &#8211;save<\/em><\/p>\n<h3>Automatic Linking:<\/h3>\n<p><em>react-native link @react-native-community\/cameraroll<\/em><\/p>\n<h3>Manual Linking<\/h3>\n<p><strong>iOS<\/strong><\/p>\n<ol>\n<li>In XCode, first, go to the project navigator, then right-click on Libraries \u279c Add Files to [project&#8217;s name]<\/li>\n<li>Go to node_modules \u279c @react-native-community\/cameraroll and add RNCCameraroll.xcodeproj<\/li>\n<li>In XCode, go to the project navigator, select your project. Add libRNCCameraroll.a to your project&#8217;s Build Phases tab \u279c Link Binary With Libraries<\/li>\n<li>Run your project.<\/li>\n<\/ol>\n<p><strong>Android<\/strong><\/p>\n<ol>\n<li>Open android\/app\/src\/main\/java\/[&#8230;]\/MainApplication.java file.<\/li>\n<li>Add import com.reactnativecommunity.cameraroll.CameraRollPackage; to the imports at the top of the file.<\/li>\n<li>Add new CameraRollPackage() to the list returned by the getPackages() method<\/li>\n<li>Append the following lines to android\/settings.gradle:<br \/>\ninclude &#8216;:@react-native-community_cameraroll&#8217; project(&#8216;:@react-native-community_cameraroll&#8217;).projectDir = new File(rootProject.projectDir, &#8216;..\/node_modules\/@react-native-community\/cameraroll\/android&#8217;)<\/li>\n<li>Insert the following lines inside the dependencies section in android\/app\/build.gradle:<br \/>\ncompile project(&#8216;:@react-native-community_cameraroll&#8217;)<\/li>\n<\/ol>\n<p><strong>Permissions:<\/strong><br \/>\nIn android and iOS user permissions are required in order to access cameraRoll and gallery. For iOS you need to add the following permissions in the info.plist file:<\/p>\n<pre>&lt;key&gt;NSPhotoLibraryAddUsageDescription&lt;\/key&gt;\r\n&lt;string&gt;$(PRODUCT_NAME) would like to save photos to your photo gallery&lt;\/string&gt;\r\n&lt;key&gt;NSPhotoLibraryUsageDescription&lt;\/key&gt;\r\n&lt;string&gt;$(PRODUCT_NAME) would like access to your photo gallery&lt;\/string&gt;<\/pre>\n<p>Where $(PRODUCT_NAME) is your application name.<br \/>\nFor Android. you need to add the following permissions in the AndroidManifest.xml file:<\/p>\n<pre>&lt;uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"\/&gt;<\/pre>\n<p>Usage:<\/p>\n<pre>import React, {Component} from 'react';\r\nimport CameraRoll from \"@react-native-community\/cameraroll\";\r\nexport default class App extends Component&lt;Props&gt;{\r\nconstructor(props){\r\nsuper(props);\r\n}\r\n_handleButtonPress = () =&gt; {\r\n   CameraRoll.getPhotos({\r\nfirst: 20,\r\n       assetType: 'Photos',\r\n     })\r\n     .then(r =&gt; {\r\n       this.setState({ photos: r.edges });\r\n     })\r\n     .catch((err) =&gt; {\r\n        \/\/Error Loading Images\r\n     });\r\n   };\r\nrender() {\r\n return (\r\n   &lt;View&gt;\r\n     &lt;Button title=\"Load Images\" onPress={this._handleButtonPress} \/&gt;\r\n     &lt;ScrollView&gt;\r\n       {this.state.photos.map((p, i) =&gt; {\r\n       return (\r\n         &lt;Image\r\n           key={i}\r\n           style={{\r\n             width: 300,\r\n             height: 100,\r\n           }}\r\n           source={{ uri: p.node.image.uri }}\r\n         \/&gt;\r\n       );\r\n     })}\r\n     &lt;\/ScrollView&gt;\r\n   &lt;\/View&gt;\r\n );\r\n}\r\n}<\/pre>\n<p>The first parameter used in above example is required for cameraRoll.<br \/>\nfirst : {number} : The number of photos needed in reverse order.<br \/>\nassetType : {string} : Specifies the filter on the asset type. Valid values are:<\/p>\n<ul>\n<li>All<\/li>\n<li>Videos<\/li>\n<li>Photos \/\/ default<\/li>\n<\/ul>\n<p>For example, to get photos and videos only, you can pass Photos|Videos also<br \/>\nThere are so many parameters present in it that you can pass for filtration.<\/p>\n<p>Result: The above example will display 20 images from the gallery on <strong>Load Images<\/strong> button press.<\/p>\n<p><small>Being the most extensively used JavaScript library, a <a href=\"https:\/\/www.studysection.com\/jquery-foundation\">jQuery certification<\/a> will add enormous value to your skill-set. jQuery provides various functionalities to the developer in order to develop complex applications with ease and efficiency.<\/small><\/p>\n<p><script>\njQuery(\"#top-view-post\").text('Attempt React Native Test Now');\njQuery(\"#top-view-post\").attr(\"href\", \"https:\/\/www.studysection.com\/react-native-advanced\");\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction React native provides many packages to access the gallery and camera. To get all types of media from mobile,<\/p>\n","protected":false},"author":1,"featured_media":3118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[358,298,509],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Getting all media from Mobile gallery in React-native<\/title>\n<meta name=\"description\" content=\"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting all media from Mobile gallery in React-native\" \/>\n<meta property=\"og:description\" content=\"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-13T06:24:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-20T12:53:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/08\/react-native-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1370\" \/>\n\t<meta property=\"og:image:height\" content=\"714\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Getting all media from Mobile gallery in React-native\",\"datePublished\":\"2020-08-13T06:24:19+00:00\",\"dateModified\":\"2023-02-20T12:53:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\"},\"wordCount\":367,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Android\/iOS\",\"Mobile\",\"React-Native\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\",\"url\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\",\"name\":\"Getting all media from Mobile gallery in React-native\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2020-08-13T06:24:19+00:00\",\"dateModified\":\"2023-02-20T12:53:55+00:00\",\"description\":\"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting all media from Mobile gallery in React-native\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting all media from Mobile gallery in React-native","description":"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/","og_locale":"en_US","og_type":"article","og_title":"Getting all media from Mobile gallery in React-native","og_description":"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.","og_url":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2020-08-13T06:24:19+00:00","article_modified_time":"2023-02-20T12:53:55+00:00","og_image":[{"width":1370,"height":714,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/08\/react-native-logo.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Getting all media from Mobile gallery in React-native","datePublished":"2020-08-13T06:24:19+00:00","dateModified":"2023-02-20T12:53:55+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/"},"wordCount":367,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Android\/iOS","Mobile","React-Native"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/","url":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/","name":"Getting all media from Mobile gallery in React-native","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2020-08-13T06:24:19+00:00","dateModified":"2023-02-20T12:53:55+00:00","description":"React native provides many packages to access gallery and camera. To get all types of media from mobile, it provides cameraRoll.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/getting-all-media-from-mobile-gallery-in-react-native\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Getting all media from Mobile gallery in React-native"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":3726,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3112"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=3112"}],"version-history":[{"count":8,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3112\/revisions"}],"predecessor-version":[{"id":6484,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3112\/revisions\/6484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/3118"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=3112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=3112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=3112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}