Video from URL working on Android 4 but not on Android 9

前端 未结 2 1642
栀梦
栀梦 2021-01-25 04:06

This code works on Android 4.4.2 but does not work on the phone with Android 9:

String url=\"http://...LINK...mp4\";
MediaController controller = new MediaContro         


        
相关标签:
2条回答
  • 2021-01-25 04:18

    Android 9.0 blocks cleartext (http) traffic by default.

    The preferred solution is to not use http URLs, but instead use https.

    You can, through network security configuration, tell Android to allow cleartext traffic for your app, but this is less secure.

    0 讨论(0)
  • 2021-01-25 04:21

    You can use the one line code in the manifest file. Its working for me.

     <application
            android:usesCleartextTraffic="true"
            android:label="@string/app_name"
            android:supportsRtl="true">
            <activity
                android:name=".EvaBotView"
                android:theme="@style/AppTheme.NoActionBar"
                android:configChanges="keyboardHidden|orientation|screenSize"/>
        </application>
    

    Inside application tag we can use android:usesCleartextTraffic="true" which can resolve this issue.

    0 讨论(0)
提交回复
热议问题