从Android Studio中的URL使用downloadmanager下载文件

时间:2018-11-04 08:16:55

标签: android-studio android-download-manager

我已使用以下代码从android studio中的url链接下载pdf文件。在模拟器中,一切正常,文件下载到下载文件夹中。但是,当我安装该应用程序时,下载未完成。请帮我解决这个问题。

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;

public class Example extends Application {
    private static Sphere sphere, sphere2, sphere3, sphere4;
    private static PerspectiveCamera camera;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        // locate random objects
        sphere = new Sphere( 150 );

        sphere.setTranslateX( 0 );
        sphere.setTranslateY( 0 );
        sphere.setTranslateZ( 400 );

        sphere.setMaterial( new PhongMaterial( Color.RED ) );


        sphere2  = new Sphere( 150 );

        sphere2.setTranslateX( 0 );
        sphere2.setTranslateY( 0 );
        sphere2.setTranslateZ( -300 );

        sphere2.setMaterial( new PhongMaterial( Color.GREEN ) );

        sphere3  = new Sphere( 150 );

        sphere3.setTranslateX( 300 );
        sphere3.setTranslateY( 0 );
        sphere3.setTranslateZ( 0 );

        sphere3.setMaterial( new PhongMaterial( Color.BLUE ) );


        sphere4  = new Sphere( 150 );

        sphere4.setTranslateX( -300 );
        sphere4.setTranslateY( 0 );
        sphere4.setTranslateZ( 0 );

        sphere4.setMaterial( new PhongMaterial( Color.YELLOW ) );

        // locate the camera
        camera = new PerspectiveCamera( true );
        camera.setTranslateX( 0 );
        camera.setTranslateY( 0 );
        camera.setTranslateZ( 0 );
        camera.setFieldOfView(90.0);
        camera.setFarClip(500.0);
        camera.setNearClip(0.01);


        // create a font of light
        PointLight light = new PointLight();

        light.setTranslateX( 0 );
        light.setTranslateY( 0 );
        light.setTranslateZ( 0 );

        Group root = new Group( sphere, sphere2, sphere3, sphere4,  light );
        Scene scene = new Scene( root, 800, 600, true);

        scene.setFill(Color.SKYBLUE);
        scene.setCamera( camera );
        scene.setOnMouseMoved( new MouseLook() );

        stage.setScene(scene);
        stage.setTitle("Mouselook rotation");
        stage.show();
    }

    static class MouseLook implements EventHandler <MouseEvent> {
        private static Rotate rotation;
        private static int oldX, newX;
        private static boolean alreadyMoved = false;

        @Override
        public void handle(MouseEvent event) {
            if ( alreadyMoved ) {
                newX = (int) event.getScreenX();

                if ( oldX < newX ) { // if mouse moved to right
                    rotation = new Rotate( 10.0,
                            // camera rotates around its location
                            camera.getTranslateX(), camera.getTranslateY(), camera.getTranslateZ(),
                            Rotate.Y_AXIS );


                } else if ( oldX > newX ) { // if mouse moved to left
                    rotation = new Rotate( -10.0,
                            // camera rotates around its location
                            camera.getTranslateX(), camera.getTranslateY(), camera.getTranslateZ(),
                            Rotate.Y_AXIS );

                }
                camera.getTransforms().addAll( rotation );

                oldX = newX;
            } else {
                oldX = (int) event.getScreenX();
                alreadyMoved = true;
            }
        }
    }
}

0 个答案:

没有答案