Java 如何获取当前登录的用户id,并使用Mysql数据库将该id作为数据上传到Android中
我想让当前用户登录到存储在共享首选项中的用户id,然后将该id作为数据或带有照片的信息插入Mysql数据库中的另一个表中 我已经尝试了很多方法来获取当前登录的用户id,然后将其作为带有照片的数据上传。我尝试在调试器中查找错误,但调试器未显示任何预期错误 这是我的Java代码Java 如何获取当前登录的用户id,并使用Mysql数据库将该id作为数据上传到Android中,java,android,mysql,Java,Android,Mysql,我想让当前用户登录到存储在共享首选项中的用户id,然后将该id作为数据或带有照片的信息插入Mysql数据库中的另一个表中 我已经尝试了很多方法来获取当前登录的用户id,然后将其作为带有照片的数据上传。我尝试在调试器中查找错误,但调试器未显示任何预期错误 这是我的Java代码 public void uploadMultipart() { //getting name for the image //getting the actual path of the i
public void uploadMultipart() {
//getting name for the image
//getting the actual path of the image
String path = getPath(filePath);
//Uploading code
try {
String uploadId = UUID.randomUUID().toString();
CA_SIGNUP_GTST user = SharedPrefManager.getInstance(UploadDOC_Activity.this).getUser();
int id = user.getId();
//Creating a multi part request
new MultipartUploadRequest(UploadDOC_Activity.this, uploadId, UPLOAD_URL)
.addFileToUpload(path,"adhar_card") //Adding file
.addParameter("expid", String.valueOf(id))
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload(); //Starting the upload
} catch (Exception exc) {
Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
}
}
//handling the image chooser activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
iv_adhar.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
//method to get the file path from uri
public String getPath(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
String document_id = cursor.getString(0);
document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
cursor.close();
cursor = getContentResolver().query(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
cursor.moveToFirst();
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
cursor.close();
return path;
}
//Requesting permission
private void requestStoragePermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
return;
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
//If the user has denied the permission previously your code will come to this block
//Here you can explain why you need this permission
//Explain here why you need this permission
}
//And finally ask for the permission
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
}
//This method will be called when the user will tap on allow or deny
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//Checking the request code of our request
if (requestCode == STORAGE_PERMISSION_CODE) {
//If permission is granted
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Displaying a toast
Toast.makeText(this, "Permission granted now you can read the storage", Toast.LENGTH_LONG).show();
} else {
//Displaying another toast if permission is not granted
Toast.makeText(this, "Oops you just denied the permission", Toast.LENGTH_LONG).show();
}
}
}
}
我希望将上载,但当我运行应用程序时,它不会显示任何错误,并且用户id和图像也不会插入数据库