0

私は現在、音楽プレーヤーで再生するファイルのダウンロードを含むコードバステストプロジェクトを行っています。基本的に、アプリケーションは自分のサーバーから.mp3ファイルをダウンロードし、アプリケーションストレージまたはユーザー定義のパス(folder-select)に保存する必要があります。 現在、ファイルを正常にダウンロードしています。カスタムパスを選択してファイルエクスプローラのアプリケーションで音楽ファイルを再生できますが、何とか音楽プレーヤーアプリケーションなどに表示されません。また、設定ファイルで外部アクセスを定義したとしても、sdcardにファイルを書き込むことはできません。 ファイルシステムにアクセスするための私の現在のコードは次のようになります。Cordova:Androidでのsdcardアクセスが機能しません

どういうわけか

app.log('Filesystem', 'Requesting filesystem...'); 
 
\t \t if (device.platform.toLowerCase() == "android") { 
 
\t \t \t app.log('Filesystem', 'Detected android device...'); 
 
\t \t \t if(window.saveInMusic && window.musicPath){ 
 
\t \t \t \t app.log('Filesystem', 'Selected storage persistent SD'); 
 
\t \t \t \t window.resolveLocalFileSystemURL(window.musicPath, app.gotFS, app.fsFail); 
 
\t \t \t } else { 
 
\t \t \t \t app.log('Filesystem', 'Selected storage persistent Internal'); 
 
\t \t \t \t window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, app.gotFS, app.fsFail); 
 
\t \t \t } 
 
\t \t } else { 
 
\t \t \t app.log('Filesystem', 'No device detected...'); 
 
\t \t \t app.log('Filesystem', 'Selected storage DEFAULT (sandbox)'); 
 
\t \t \t window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.gotFS, app.fsFail); 
 
\t \t }

、すべてcordova.file.external * directorysはヌル(プラグインmdのファイルに記載されたように)とされていますexternalRootDirectoryは "storage/emulated/0/appdir"(sdcardパスを返します)を返しています。私は次のようになりconfig.xmlにとのAndroidManifest.xmlの権限を確認しています

<?xml version='1.0' encoding='utf-8'?> 
 
<widget id="com.someorg.appname" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
 
    <name>AppName</name> 
 
    <description> 
 
     A basic Framework7 template for PhoneGap. 
 
    </description> 
 
    <author email="[email protected]" href="http://cordova.io"> 
 
     Apache Cordova Team 
 
    </author> 
 
    <content src="index.html" /> 
 
    <access origin="*" /> 
 
    <allow-intent href="http://*/*" /> 
 
    <allow-intent href="https://*/*" /> 
 
    <allow-intent href="tel:*" /> 
 
    <allow-intent href="sms:*" /> 
 
    <allow-intent href="mailto:*" /> 
 
    <allow-intent href="geo:*" /> 
 
    <platform name="android"> 
 
     <preference name="android-minSdkVersion" value="14" /> 
 
\t \t <preference name="AndroidPersistentFileLocation" value="Compatibility" /> 
 
\t \t <preference name="AndroidExtraFilesystems" value="sdcard,cache" /> 
 
     <allow-intent href="market:*" /> 
 
    </platform> 
 
    <platform name="ios"> 
 
     <allow-intent href="itms:*" /> 
 
     <allow-intent href="itms-apps:*" /> 
 
     <preference name="BackupWebStorage" value="none" /> 
 
    </platform> 
 
    <preference name="DisallowOverscroll" value="true" /> 
 
    <plugin name="cordova-plugin-whitelist" spec="~1.2.0" /> 
 
    <plugin name="cordova-plugin-console" spec="~1.0.1" /> 
 
    <plugin name="cordova-plugin-statusbar" spec="~1.0.1" /> 
 
\t <plugin name="cordova-plugin-compat" spec="~1.1.0" /> 
 
\t <plugin name="cordova-plugin-device" spec="~1.1.5" /> 
 
\t <plugin name="cordova-plugin-file" spec="~4.3.2" /> 
 
\t <plugin name="cordova-plugin-file-transfer" spec="~1.6.2" /> 
 
\t <plugin spec="https://github.com/ourcodeworld/cordova-ourcodeworld-filebrowser.git#96a57ef" source="git" /> 
 
</widget>

<?xml version='1.0' encoding='utf-8'?> 
 
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.someorg.appname" xmlns:android="http://schemas.android.com/apk/res/android"> 
 
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> 
 
    <uses-permission android:name="android.permission.INTERNET" /> 
 
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true"> 
 
     <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"> 
 
      <intent-filter android:label="@string/launcher_name"> 
 
       <action android:name="android.intent.action.MAIN" /> 
 
       <category android:name="android.intent.category.LAUNCHER" /> 
 
      </intent-filter> 
 
     </activity> 
 
     <activity android:label="Our Code World filepicker" android:name="com.ourcodeworld.plugins.filebrowser.DialogShowPicker"> 
 
      <intent-filter> 
 
       <action android:name="com.ourcodeworld.plugins.filebrowser.DialogShowPicker" /> 
 
       <category android:name="android.intent.category.DEFAULT" /> 
 
      </intent-filter> 
 
     </activity> 
 
     <activity android:label="Filepicker" android:name="com.nononsenseapps.filepicker.FilePickerActivity" android:theme="@style/FilePickerTheme"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.GET_CONTENT" /> 
 
       <category android:name="android.intent.category.DEFAULT" /> 
 
      </intent-filter> 
 
     </activity> 
 
    </application> 
 
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="25" /> 
 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
 
</manifest>
アプリケーションは、インストール時にこれらの権限を求め、実際にあります。 私は、回避策(folderpicker)を実装して、手動でsdcardパスを選択しました。残念ながら、私はそれが失敗している私のgetDirectory関数を試してみてください。

gotFS: function(fileSystem){ 
 
\t \t window.fileSystem = fileSystem; 
 
\t \t app.log('Filesystem', 'Filesystem got!'); 
 
\t \t var entry = ""; 
 
\t \t if (device.platform.toLowerCase() == "android") { 
 
\t \t \t entry = fileSystem; 
 
\t \t } else { 
 
\t \t \t entry = fileSystem.root; 
 
\t \t } 
 
\t \t app.log('Filesystem', 'Setting up directory...'); 
 
\t \t entry.getDirectory(window.appRootDirName, { 
 
\t \t \t create: true, 
 
\t \t \t exclusive: false 
 
\t \t }, app.dirReady, app.fsFail); 
 
\t },

は、私はすでにtrought多くのstackoverflowのページやドキュメントを検索しましたが、私は、任意の解決策を考え出すしませんでした。最新のコードバ6.5をインストールし、すべてのプラグインを最新の安定版に更新しました。私はどんなアドバイスにも満足しています。

更新:をより明確にするために、アプリケーションのユーザーは、彼がに使用され、管理し、アプリthroughtそれらを開くことがないようダウンロードされたメディアファイルを使用することができるはずです。

答えて

0

hereをご覧ください。プラグインcordova-plugin-file-opener2がこの問題を解決しました!

+0

これがどのように問題を解決しているのかわかりません。問題は、ダウンロードしたファイルがサンドボックスのような音楽プレーヤーのような他のアプリケーションによって認識されないことです。私は、私はエミュレートされたものの代わりに永続的な場所を取得するためにresolveFileSystemの代わりにresolveLocalFileSystemURLを使用しなければならないことを読んだが、これもうまくいかなかった。 – user285814

+0

@ user285814 'opener2'はエミュレートされた場所をパーマネントに変換します。私の場合、システムは' PDF's'と 'MP3'を正しく開きました。あなたがしているのは、あなたが望む 'MIME TYPE'を渡すだけです。 –

+0

見てください:https://github.com/pwlin/cordova-plugin-file-opener2 –

関連する問題