Skip to content

Commit

Permalink
File picker not able to select files on SD card
Browse files Browse the repository at this point in the history
  • Loading branch information
ieugen committed Jan 5, 2023
1 parent 23f1612 commit ddf41a3
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-app')
implementation project(':capacitor-filesystem')
implementation project(':capawesome-capacitor-file-picker')
implementation project(':send-intent')

}
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@
<!-- Permissions -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
4 changes: 4 additions & 0 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"pkg": "@capacitor/filesystem",
"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
},
{
"pkg": "@capawesome/capacitor-file-picker",
"classpath": "io.capawesome.capacitorjs.plugins.filepicker.FilePickerPlugin"
},
{
"pkg": "send-intent",
"classpath": "de.mindlib.sendIntent.SendIntent"
Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/
include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')

include ':capawesome-capacitor-file-picker'
project(':capawesome-capacitor-file-picker').projectDir = new File('../node_modules/@capawesome/capacitor-file-picker/android')

include ':send-intent'
project(':send-intent').projectDir = new File('../node_modules/send-intent/android')
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"dependencies": {
"@babel/helper-environment-visitor": "^7.18.2",
"@bity/oauth2-auth-code-pkce": "^2.13.0",
"@capacitor/android": "^4.0.0",
"@capacitor/app": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/android": "^4.6.1",
"@capacitor/app": "^4.1.1",
"@capacitor/core": "^4.6.1",
"@capacitor/filesystem": "^4.1.4",
"@capawesome/capacitor-file-picker": "^0.5.2",
"aos": "^2.3.4",
"bowser": "^2.11.0",
"classnames": "^2.2.6",
Expand Down
64 changes: 64 additions & 0 deletions src/components/SyncServiceSignIn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
gitLabProjectIdFromURL,
} from '../../sync_backend_clients/gitlab_sync_backend_client';

import { Filesystem } from '@capacitor/filesystem';
import { FilePicker } from '@capawesome/capacitor-file-picker';

import { Dropbox } from 'dropbox';
import _ from 'lodash';

Expand Down Expand Up @@ -149,6 +152,63 @@ function GitLab() {
);
}

const pickFiles = async () => {
// 1. Request permissions
await Filesystem.requestPermissions();
// 2. Pick files
const result = await FilePicker.pickFiles();
const file = result.files[0];

alert('Selected file is' +
JSON.stringify(file) +
' ' + JSON.stringify(result));
return result
};

function LocalStorage() {
const [isVisible, setIsVisible] = useState(false);
const toggleVisible = () => setIsVisible(!isVisible);

const defaultOrgDirectory = '/org';
const [orgDirectory, setOrgDirectory] = useState(defaultOrgDirectory);

pickFiles();

return (
<div id="localStorageSelect">
<h2>
<a href="#localstorage" onClick={toggleVisible} style={{ textDecoration: 'none' }}>
Local Storage
</a>
</h2>
{isVisible && (
<>
<form
onSubmit={(event) => {
event.preventDefault();
persistField('authenticatedSyncService', 'LocalStorage');
persistField('orgDirectory', orgDirectory);
}}
>
<p>
<label htmlFor="input-org-dir">Org directory:</label>
<input
id="input-org-dir"
name="orgDir"
type="text"
value={orgDirectory}
className="textfield"
onChange={(e) => setOrgDirectory(e.target.value)}
/>
</p>
<input type="submit" value="Use directory" />
</form>
</>
)}
</div>
);
}

export default class SyncServiceSignIn extends PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -190,6 +250,10 @@ export default class SyncServiceSignIn extends PureComponent {
<WebDAVForm />
</div>

<div className="sync-service-container">
<LocalStorage />
</div>

<footer className="sync-service-sign-in__help-text">
<p>
For questions regarding synchronization back-ends, please consult the{' '}
Expand Down
16 changes: 13 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1485,12 +1485,12 @@
resolved "https://registry.yarnpkg.com/@bity/oauth2-auth-code-pkce/-/oauth2-auth-code-pkce-2.13.0.tgz#cee077db75182b01e9b576a52ee408480d39bdc5"
integrity sha512-jAVsbLIVHvo0Lm6sj2t3ltiLbWKvTlkVflHCiV9DRk1w9FBEOjpJD7OJXkeWBY0Vgr+XiGIm80yJa+sa8XpnWQ==

"@capacitor/android@^4.0.0":
"@capacitor/android@^4.6.1":
version "4.6.1"
resolved "https://registry.yarnpkg.com/@capacitor/android/-/android-4.6.1.tgz#50e437934bf535eb839266df4d60204aace79561"
integrity sha512-Hnh1tmUr1SP67U6D6ry5I5BEBSN/1nkBAIjQIqf5tF82WNxKbpbC6GfkHE4hMJZinRTrCf36LkrdP8srh7SxoA==

"@capacitor/app@^4.0.0":
"@capacitor/app@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@capacitor/app/-/app-4.1.1.tgz#47329e19ecc080bc2934be86566a7673e0f94e5c"
integrity sha512-SJcJA1rhFQyeH6eLfUEbdKkHzAwzahJNVPNXmU88fdmXpMgM2dJGzZj1vrm6e21aQq+Z4aBVLJ2RCdj92zD7wg==
Expand Down Expand Up @@ -1547,13 +1547,23 @@
dependencies:
tslib "^2.1.0"

"@capacitor/core@^4.0.0":
"@capacitor/core@^4.6.1":
version "4.6.1"
resolved "https://registry.yarnpkg.com/@capacitor/core/-/core-4.6.1.tgz#55428b1b2b8d8bb2839fff42f8dfcdbde8d17fb9"
integrity sha512-7A2IV9E8umgu9u0fChUTjQJq+Jp25GJZMmWxoQN/nVx/1rcpFJ4m1xo3NPBoIRs+aV7FR+BM17mPrnkKlA8N2g==
dependencies:
tslib "^2.1.0"

"@capacitor/filesystem@^4.1.4":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@capacitor/filesystem/-/filesystem-4.1.4.tgz#021ef707ca199d554042ebc85151416dec07020a"
integrity sha512-ivko1RNK4hq63xhMacq8D6D97N5/SAafTsrmY/pghYrG6Cl2SEY0+IgRu7V9/VWeN3FSplyUPucjUTAFQxXN5g==

"@capawesome/capacitor-file-picker@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@capawesome/capacitor-file-picker/-/capacitor-file-picker-0.5.2.tgz#566a738acd5574df8556ca29e149a3e354c52e93"
integrity sha512-tJv3s0diZZf5+igsjWlsOBp9CQGs11lsEQ7+biimOCl61pr0GDcDieNWnsW7G+Ge9CzcWAHGffDW0QGiCR52XA==

"@cnakazawa/watch@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef"
Expand Down

0 comments on commit ddf41a3

Please sign in to comment.