java - 在 Android Studio 中,我可以使用 api 同步数据
问题描述
在 Android Studio 中,我无法使用 api 同步数据。由于我的代码是异步的,所以当我第二次按下按钮时它就会出现。
我想做的是使用api同步获取数据。
我的代码:
public class MainActivity extends AppCompatActivity {
private WebView webView;
private CustomWebViewClient webViewClient;
private String Url = "";
private String LiveBroadCastUrl;
ProgressDialog mProgressDialog;
RelativeLayout relativeLayout;
RelativeLayout permissionsMedia;
Button btnNoInternetConnections;
Button permissionsButton;
Button refresPermissons;
ImageView permissionsLogo;
ImageView noInternetLogo;
RequestQueue mQueue;
String time;
String responsestate;
Context context=this;
//public Context context;
public static int REQUEST_PERMISSION=1;
private static final String TAG = MainActivity.class.getSimpleName();
private static final int FILECHOOSER_RESULTCODE = 1;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
// the same for Android 5.0 methods only
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
ProgressBar progressBarWeb;
private String sURL,sFileName,sUser;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, URL, null, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject jsonObject) {
try {
time = jsonObject.getString("CustomObject");
responsestate= jsonObject.getString("CustomResponseState");
//Log.e("gelen değer",time);
} catch (JSONException e) {
//Log.e("hata","catche düştü");
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "Hata Oluştu", Toast.LENGTH_SHORT).show();
}
});
mQueue.add(request);
}
解决方案
推荐阅读
- docker-compose - 在 docker-compose 中使用 bash 命令设置 Rethinkdb
- python - Python追加到字典列表
- angular - Angular 6 和 Karma/Jasmine 问题 - 没有 Angular CLI
- powershell - 使用 Powershell 从 OneDrive 下载文件
- java - 格式为 2018-11-26T15:12:03.000-0800 的字符串到格式为“M/dd/yy HH:mm:ss a z”的 java.time.localdatetime 转换抛出异常
- c++ - 声明后更改别名
- angular - Angular 6,指令 ngOnChanges 不适用于 lambda 表达式?
- java - Spring Boot - TestRestTemplate LocalDate of body null
- javascript - 在 Chart.js 多条形图中,有没有办法突出显示单个类别?
- matrix - 从现有网格创建 2D 圆