尝试从我的Web服务器读取文本文件,但未找到文件错误

问题描述 投票:0回答:1

我在android应用中有以下代码。从Android Studio在我的手机上运行该应用程序时,该应用程序可以正常工作并从我的网站读取文件,但是在生成构建并在Google Play商店上发布并从Google商店安装后,我在运行应用程式。清单文件中有Internet许可。

<uses-permission android:name="android.permission.INTERNET" />

该文件存在于服务器上,我可以从移动设备使用Web浏览器打开该文件。我已经尝试过使用http://leevalleyboats.co.uk/textfiles/videos.txthttp://www.leevalleyboats.co.uk/textfiles/videos.txt

public class getVideoList extends AsyncTask<Void, Void, Void> {
    int i = 0;
    String TextFileURL = "http://leevalleyboats.co.uk/textfiles/videos.txt";

    @Override
    protected Void doInBackground(Void... params) {

        try {
            url = new URL(TextFileURL);
            HttpURLConnection con=(HttpURLConnection)url.openConnection();
            InputStream is=con.getInputStream();
            BufferedReader bufferReader=new BufferedReader(new InputStreamReader(is));
            while((TextHolder2 = bufferReader.readLine()) != null) {
                 TextHolder1 = TextHolder2;
                videos[i] = TextHolder2;
                i++;
            }
            is.close();
            bufferReader.close();

        } catch (IOException malformedURLException) {
            malformedURLException.printStackTrace();
            TextHolder1 = malformedURLException.toString();
           // TextHolder1= "File Not Found";

        }
        return null;
    }
  xmlns:tools="http://schemas.android.com/tools"
    package="co.uk.leevalleyboats.lvbc">
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
        tools:ignore="GoogleAppIndexingWarning">

        <activity android:name=".MoleVideoActivity"/>

        <activity android:name=".TestActivity" />

        <meta-data
            android:name="com.google.android.gms.car.application"
            android:resource="@xml/automotive_app_desc" />

        <activity
            android:name=".LocksVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".DrivingVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".ToadVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".OtterVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".OwlVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".FoxVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".BadgerVideoActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity android:name=".VideoListActivity" />
        <activity android:name=".NotificationReceiver" />
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="XXXXXXXXXXXXXXXXXXX" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".WaitingActivity" />
        <activity android:name=".DayBoatDetailsActivity" />
        <activity android:name=".SmallBoatActivity" />
        <activity android:name=".PassengerBoatActivity" />
        <activity android:name=".WaitingnumberActivity" />
        <activity android:name=".a4SeaterVideo" android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity android:name=".DirectionsVideo"
            android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name=".RowVideo"
            android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name=".PedVideo"
            android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name=".RattyVideo" android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity android:name=".PortLeeVideo"  android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name=".a7SeaterVideo"  android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name=".a5SeaterVideo" android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity android:name=".LadyVideoActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity android:name=".PrideVideoActivity" android:configChanges="keyboardHidden|orientation|screenSize" />

    </application>

</manifest>
android
1个回答
0
投票

我的声誉欠佳,无法发表评论,因此将其发布为答案。我猜这是因为从Android 9开始,不允许明文HTTP流量。使用https代替http。

检查日志猫,您可能会发现java.io.IOException:不允许到leevalleyboats.co.uk的明文HTTP通信。如果发现此问题,则将URL替换为:字符串TextFileURL =“ https://leevalleyboats.co.uk/textfiles/videos.txt”;

© www.soinside.com 2019 - 2024. All rights reserved.