Android从url读取文件

时间:2017-05-12 07:59:24

标签: android

我创建了android应用程序来流式传输在线广播电台,但它不起作用。我想从url读取ip地址并将其分配给字符串,当用户选择收音机收听时我应该为该字符串添加端口!! !

    public class BackgroundService extends Service implements MediaPlayer.OnCompletionListener
{
    MediaPlayer mediaPlayer;
    private String STREAM_URL;
    final String textSource = "http://audiophileradio.stream/Ip.txt";

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate()
    {
        new MyTask().execute();

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        String radio = sharedPreferences.getString("station", "8000");

        if (radio != null && radio.equals("8000"))
        {
            STREAM_URL = "http://178.149.88.126:8000/";
        }
        if (radio != null && radio.equals("8010"))
        {
            STREAM_URL = "http://178.149.88.126:8010/";
        }
        if (radio != null && radio.equals("8020"))
        {
            STREAM_URL = "http://178.149.88.126:8020/";
        }
        if (radio != null && radio.equals("8030"))
        {
            STREAM_URL = "http://178.149.88.126:8030/";
        }

        mediaPlayer = new MediaPlayer();
        try
        {
            mediaPlayer.setDataSource(STREAM_URL);
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        mediaPlayer.setOnCompletionListener(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        if (!mediaPlayer.isPlaying())
        {
            try
            {
                mediaPlayer.reset();
                mediaPlayer.setDataSource(STREAM_URL);
                mediaPlayer.prepareAsync();

                mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
                {
                    @Override
                    public void onPrepared(MediaPlayer mp)
                    {
                        mediaPlayer.start();
                    }
                });
            } catch (IOException e)
            {
                e.printStackTrace();
            }

        }
        return START_STICKY;
    }

    public void onDestroy() {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
        }
        mediaPlayer.release();
    }

    public void onCompletion(MediaPlayer _mediaPlayer) {
        stopSelf();
    }


    @Override
    public boolean onUnbind(Intent intent)
    {
        return super.onUnbind(intent);
    }

    private class MyTask extends AsyncTask<Void, Void, Void>
    {

        String textResult;

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

            URL textUrl;

            try {
                textUrl = new URL(textSource);

                BufferedReader bufferReader
                        = new BufferedReader(new InputStreamReader(textUrl.openStream()));

                String StringBuffer;
                String stringText = "";
                while ((StringBuffer = bufferReader.readLine()) != null) {
                    stringText += StringBuffer;
                }
                bufferReader.close();

                textResult = stringText;
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                textResult = e.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                textResult = e.toString();
            }

            return null;

        }

        @Override
        protected void onPostExecute(Void result) {

            Log.d("DebugTag", "Value2: " + textResult);

            super.onPostExecute(result);
        }
    }
}
05-12 10:35:48.625 17340-17340/? I/SELinux: Function: selinux_android_load_priority [0], There is no sepolicy file.

05-12 10:35:48.625 17340-17340/? I/SELinux: Function: selinux_android_load_priority [1], There is no sepolicy version file.

05-12 10:35:48.625 17340-17340/? I/SELinux: Function: selinux_android_load_priority , priority version is VE=SEPF_GT-I9301I_4.4.2_0055


05-12 10:35:48.625 17340-17340/? I/SELinux: selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
05-12 10:35:48.625 17340-17340/? D/dalvikvm: Late-enabling CheckJNI
05-12 10:35:48.835 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.view.Window.setStatusBarColor, referenced from method audiophileradio.example.com.audiophileradio.MainActivity.onCreate
05-12 10:35:48.835 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 21917: Landroid/view/Window;.setStatusBarColor (I)V
05-12 10:35:48.835 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0081
05-12 10:35:48.865 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
05-12 10:35:48.865 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve interface method 21896: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
05-12 10:35:48.865 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve interface method 21898: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve interface method 21902: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 505: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 527: Landroid/content/res/TypedArray;.getType (I)I
05-12 10:35:48.875 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
05-12 10:35:48.965 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
05-12 10:35:48.965 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 316: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
05-12 10:35:48.965 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 468: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 470: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-12 10:35:49.175 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-12 10:35:49.185 17340-17340/audiophileradio.example.com.audiophileradio E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
05-12 10:35:49.185 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve instanceof 150 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
05-12 10:35:49.185 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
05-12 10:35:49.315 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: setProgressDrawable drawableHeight = 24
05-12 10:35:49.335 17340-17340/audiophileradio.example.com.audiophileradio D/AbsSeekBar: AbsSeekBar Constructor: misSeebarAnimationAvailable = false
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: setProgressDrawable drawableHeight = 24
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: setProgressDrawable getHeight() = 0
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: left = 0
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: top = 0
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: right = -64
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: bottom = 0
05-12 10:35:49.345 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: mProgressDrawable.setBounds()
05-12 10:35:49.365 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer-JNI: native_setup
05-12 10:35:49.365 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: constructor
05-12 10:35:49.365 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: setListener
05-12 10:35:49.365 17340-17340/audiophileradio.example.com.audiophileradio E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
05-12 10:35:49.405 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer-JNI: native_setup
05-12 10:35:49.405 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: constructor
05-12 10:35:49.405 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: setListener
05-12 10:35:49.405 17340-17340/audiophileradio.example.com.audiophileradio E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.headsUpContentView
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve instance field 14
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x5b at 0x005d
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.headsUpContentView
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve instance field 14
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x5b at 0x004c
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.headsUpContentView
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: DexOpt: unable to optimize instance field ref 0x000e at 0x54 in Landroid/support/v7/app/NotificationCompat;.addHeadsUpToBuilderLollipop
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.headsUpContentView
05-12 10:35:49.415 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: DexOpt: unable to optimize instance field ref 0x000e at 0x61 in Landroid/support/v7/app/NotificationCompat;.addHeadsUpToBuilderLollipop
05-12 10:35:49.485 17340-17340/audiophileradio.example.com.audiophileradio I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
                                                                                         OpenGL ES Shader Compiler Version: E031.24.00.07
                                                                                         Build Date: 01/27/14 Mon
                                                                                         Local Branch: base_au149_adreno_au169_patches
                                                                                         Remote Branch: 
                                                                                         Local Patches: 
                                                                                         Reconstruct Branch: 
05-12 10:35:49.605 17340-17340/audiophileradio.example.com.audiophileradio D/OpenGLRenderer: Enabling debug mode 0
05-12 10:35:49.615 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: left = 0
05-12 10:35:49.615 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: top = 0
05-12 10:35:49.615 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: right = 568
05-12 10:35:49.615 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: bottom = 68
05-12 10:35:49.615 17340-17340/audiophileradio.example.com.audiophileradio D/ProgressBar: updateDrawableBounds: mProgressDrawable.setBounds()
05-12 10:35:49.625 17340-17340/audiophileradio.example.com.audiophileradio I/dalvikvm: Could not find method android.support.v7.widget.LinearLayoutCompat.drawableHotspotChanged, referenced from method android.support.design.internal.ForegroundLinearLayout.drawableHotspotChanged
05-12 10:35:49.625 17340-17340/audiophileradio.example.com.audiophileradio W/dalvikvm: VFY: unable to resolve virtual method 18400: Landroid/support/v7/widget/LinearLayoutCompat;.drawableHotspotChanged (FF)V
05-12 10:35:49.625 17340-17340/audiophileradio.example.com.audiophileradio D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
05-12 10:36:19.895 17340-17340/audiophileradio.example.com.audiophileradio E/Play: onPlay
05-12 10:36:19.955 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer-JNI: native_setup
05-12 10:36:19.955 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: constructor
05-12 10:36:19.965 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: setListener
05-12 10:36:19.965 17340-17340/audiophileradio.example.com.audiophileradio E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
05-12 10:36:20.005 17340-17340/audiophileradio.example.com.audiophileradio E/MediaPlayer: Unable to create media player
05-12 10:36:20.005 17340-17352/audiophileradio.example.com.audiophileradio V/MediaPlayer: message received msg=8, ext1=0, ext2=0
05-12 10:36:20.005 17340-17352/audiophileradio.example.com.audiophileradio V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err: java.io.IOException: setDataSource failed.: status=0x80000000
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer._setDataSource(Native Method)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1317)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1240)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at audiophileradio.example.com.audiophileradio.BackgroundService.onCreate(BackgroundService.java:107)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2736)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.access$1900(ActivityThread.java:169)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.os.Looper.loop(Looper.java:136)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5476)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at dalvik.system.NativeStart.main(Native Method)
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: isPlaying: no active player
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer-JNI: isPlaying: 0
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer-JNI: reset
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio V/MediaPlayer: reset
05-12 10:36:20.015 17340-17352/audiophileradio.example.com.audiophileradio V/MediaPlayer: message received msg=8, ext1=0, ext2=0
05-12 10:36:20.015 17340-17352/audiophileradio.example.com.audiophileradio V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio E/MediaPlayer: Unable to create media player
05-12 10:36:20.015 17340-17340/audiophileradio.example.com.audiophileradio W/System.err: java.io.IOException: setDataSource failed.: status=0x80000000
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer._setDataSource(Native Method)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1317)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1240)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at audiophileradio.example.com.audiophileradio.BackgroundService.onStartCommand(BackgroundService.java:124)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2883)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.access$2200(ActivityThread.java:169)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.os.Looper.loop(Looper.java:136)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5476)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
05-12 10:36:20.025 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
05-12 10:36:20.035 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
05-12 10:36:20.035 17340-17340/audiophileradio.example.com.audiophileradio W/System.err:     at dalvik.system.NativeStart.main(Native Method)
05-12 10:36:20.195 17340-19228/audiophileradio.example.com.audiophileradio I/System.out: Thread-66912(HTTPLog):isShipBuild true
05-12 10:36:20.195 17340-19228/audiophileradio.example.com.audiophileradio I/System.out: Thread-66912(HTTPLog):SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
05-12 10:36:20.425 17340-19228/audiophileradio.example.com.audiophileradio D/MyTag: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

1 个答案:

答案 0 :(得分:0)

可以使用OkHttp:

在Gradle中添加此代码

compile 'com.squareup.okhttp3:okhttp:3.7.0'

使用:

OkHttpClient client = new OkHttpClient();
request = new Request.Builder().url("http://audiophileradio.stream/Ip.txt")
                     .addHeader("X-CSRFToken", csrftoken)
                     .addHeader("Content-Type", "application/json")
                     .build();
response = getClient().newCall(request).execute();

InputStream in = response.body().byteStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String result, line = reader.readLine();
result = line;
while((line = reader.readLine()) != null) {
    result += line;
}
System.out.println(result);
response.body().close();