PhoneGap的Andr​​oid的LocalFileSystem没有定义定义、Andr、PhoneGap、LocalFileSystem

2023-09-04 05:09:24 作者:感受

我有我的PhoneGap的应用程序访问Android文件系统的存储目的的问题。我搜索,发现很多不-MY-情况的解决方案!

I have a problem for accessing Android File System for storage purpose in my phonegap application. I've searched and found lots of not-my-situation solutions!

我知道deviceready的必要性被解雇,并检查,它被解雇了。所以phonegap.js加载完美!

I know about the necessity of deviceready to be fired and checked and it got fired. So the phonegap.js is loaded perfectly!

我觉得我所要求的文件权限,并在我的清单和配置文件的功能。在这里,他们是:

I think I requested the file permissions and have features in my manifest and config file. here they are:

config.xml文件:

config.xml:

    <feature name="http://api.phonegap.com/1.0/device" />
    <feature name="http://api.phonegap.com/1.0/battery"/>
    <feature name="http://api.phonegap.com/1.0/camera"/>
    <feature name="http://api.phonegap.com/1.0/contacts"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/geolocation"/>
    <feature name="http://api.phonegap.com/1.0/media"/>
    <feature name="http://api.phonegap.com/1.0/network"/>
    <feature name="http://api.phonegap.com/1.0/notification"/>
    <preference name="permissions" value="none" />
    <preference name="orientation" value="default" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="disable-cursor" value="false" />
    <preference name="android-minSdkVersion" value="7" />
    <preference name="android-installLocation" value="auto" />
    <icon src="icon.png" />
    <icon gap:density="ldpi" gap:platform="android" src="res/icon/android/icon-36-ldpi.png" />
    <icon gap:density="mdpi" gap:platform="android" src="res/icon/android/icon-48-mdpi.png" />
    <icon gap:density="hdpi" gap:platform="android" src="res/icon/android/icon-72-hdpi.png" />
    <icon gap:density="xhdpi" gap:platform="android" src="res/icon/android/icon-96-xhdpi.png" />
    <access origin="*" />
    <content src="index.html" />
</widget>

AndroidManifest.xml中:

AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="com.pakhshyaran.kara" 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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission." />
    <application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="Kara" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
</manifest>

和这里的错误引发了我的code部分:

and here is the error throwing part of my code:

$(document).ready(function () {
    document.addEventListener("deviceready", onDeviceReady, false);
});
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { //throws the 'Uncaught ReferenceError: LocalFileSystem is not defined' error
        fileSystem = fileSystem;
    }, function (evt) {
        alert(evt.target.error.code);
    });
}

不过,我得到一个原因,我没有任何想法的错误!请给我你的想法。我AP preciate非常喜欢。

But I get the error for a reason I don't have any idea about! Please give me your thought. I appreciate it very much.

PS:我使用的PhoneGap 3.0

PS: I'm using phonegap 3.0!

推荐答案

您使用PhoneGap的CLI来构建你的项目?然后,你可能会错过补充文件的插件到您的项目。除了配置在的config.xml AndroidManifiest.xml 您需要的code的插件。你可以把它添加到您的项目有:

Are you using phonegap cli to build your project? Then you might have missed adding the File plugin to your project. Besides configuring in config.xml and AndroidManifiest.xml you need the code for the plugin. You can add it to your project with:

$ phonegap plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git 

请在文档页面的顶部:http://docs.phonegap.com/en/3.0.0/cordova_file_file.md.html#LocalFileSystem

您还可以查看文件的安卓/资产/ WWW / cordova_plugins.js 来看看 window.LocalFileSystem 实际上定义。寻找财产以后是这样的:

You can also check the file android/assets/www/cordova_plugins.js to see if window.LocalFileSystem is actually defined. Look for somthing like this:

{
    "file": "plugins/org.apache.cordova.core.file/www/FileSystem.js",
    "id": "org.apache.cordova.core.file.FileSystem",
    "clobbers": [
        "window.FileSystem"
    ]
},