Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Nativescript插件上的异步问题,强制使用.get_Java_Android_Asynchronous_Nativescript - Fatal编程技术网

Java Nativescript插件上的异步问题,强制使用.get

Java Nativescript插件上的异步问题,强制使用.get,java,android,asynchronous,nativescript,Java,Android,Asynchronous,Nativescript,我在java类中有一个JSONobject,可以从我的Nativescript插件调用它 它被发送一个url以下载并保存在手机上(未显示保存类),然后返回一个包含高度和宽度的对象,该对象将返回给插件 我想显示progress对话框,但在使用Async和.get时,这是不可能的,我看不到任何其他方法可以从onPostExecute()下载映像并将JSONObject返回到等待插件 这是ansync函数。每个人都说要将所有代码放在onPostExecute()部分,但这是如何工作的,我需要公共JSO

我在java类中有一个JSONobject,可以从我的Nativescript插件调用它

它被发送一个url以下载并保存在手机上(未显示保存类),然后返回一个包含高度和宽度的对象,该对象将返回给插件

我想显示progress对话框,但在使用Async和.get时,这是不可能的,我看不到任何其他方法可以从onPostExecute()下载映像并将JSONObject返回到等待插件

这是ansync函数。每个人都说要将所有代码放在onPostExecute()部分,但这是如何工作的,我需要公共JSONObject downloadImage根据维度返回对象,我不能在这里这样做

private class DownloadImage extends AsyncTask<String, Void, Bitmap> {
    private int imagenumber;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Bitmap doInBackground(Strng... imageUrl) {

        Bitmap bitmap = null;
        try {
            // Download Image from URL
            InputStream input = new java.net.URL(imageURL).openStream();
            // Decode Bitmap
            bitmap = BitmapFactory.decodeStream(input);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        //It is redundant here, I would like this to do what happens in the public JSONObject downloadImage JSON
    }
}
私有类下载映像扩展异步任务{
私人int图像编号;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
}
@凌驾
受保护位图doInBackground(Strng…imageUrl){
位图=空;
试一试{
//从URL下载图像
InputStream输入=新的java.net.URL(imageURL.openStream();
//解码位图
位图=BitmapFactory.decodeStream(输入);
}捕获(例外e){
e、 printStackTrace();
}
返回位图;
}
@凌驾
受保护的void onPostExecute(位图结果){
//这在这里是多余的,我想这样做在公共JSONObject downloadImage JSON中发生的事情
}
}

有一个
nativescript downloadmanager
-插件,可以帮助您下载文件。插件将在下载图像时显示进度条

private class DownloadImage extends AsyncTask<String, Void, Bitmap> {
    private int imagenumber;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Bitmap doInBackground(Strng... imageUrl) {

        Bitmap bitmap = null;
        try {
            // Download Image from URL
            InputStream input = new java.net.URL(imageURL).openStream();
            // Decode Bitmap
            bitmap = BitmapFactory.decodeStream(input);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        //It is redundant here, I would like this to do what happens in the public JSONObject downloadImage JSON
    }
}