大家好,我想通过 Retrofit2 发布图像和其他数据。我正在用一张图像发送数据。
所有其他信息都在存储,但我的图像没有存储。当我与邮递员一起测试时,它可以工作。
请指导我在我的代码中缺少的地方
这是有效的邮递员代码片段
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
RequestBody body = RequestBody.create(mediaType, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\ntest6@gmail.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n123456\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nTest\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"phone\"\r\n\r\n1234567890\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"; filename=\"03.JPG\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
Request request = new Request.Builder()
.url("https://"url"/api/v1/sign-up")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "2dd038d9-5f52-fcd0-9331-445eaf35c230")
.build();
Response response = client.newCall(request).execute();
Run Code Online (Sandbox Code Playgroud)
以下是邮递员请求图片:
这是我的改造 api
@Multipart
@POST("sign-up")
Call<SignUpResponse> getSignUpResponse(
@Part("email") RequestBody email,
@Part("password") RequestBody password,
@Part("name") RequestBody name,
@Part("phone") RequestBody phone,
@Part MultipartBody.Part image
//@Part("image") RequestBody image // i have …Run Code Online (Sandbox Code Playgroud) 始终在线的 VPN 交换机可以以编程方式打开吗?
我已经添加了设备管理员权限。在那之后,我设置了始终与设备管理员一起使用
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(this, DeviceAdminReceiver.class);
isAdminApp = mDPM.isAdminActive(mDeviceAdminSample);
if (isAdminApp) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mDPM.setAlwaysOnVpnPackage(mDeviceAdminSample,"", true);
}
} catch (PackageManager.NameNotFoundException namenotfoundexception) {
namenotfoundexception.printStackTrace();
} catch (Exception ex) {
}
}
Run Code Online (Sandbox Code Playgroud)
但它并没有启用始终开启。
我已经添加了包名
mDPM.setAlwaysOnVpnPackage(mDeviceAdminSample,"my.app.package.name", true);
但仍然没有启用开关。
那么这段代码在做什么呢?如何以编程方式启用它?
我希望这就像下图
在我运行 react-native 应用程序时创建项目后,
它给了我这个错误。
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> Uninitialized object exists on backward branch 142
Exception Details:
Location:
com/android/build/gradle/internal/pipeline/VariantInfoImpl.<init>(Lcom/android/build/gradle/internal/scope/VariantScope;)V @200: goto
Reason:
Error exists in the bytecode
Bytecode:
0x0000000: 2b12 3cb8 0034 2a2b b900 4201 0059 1244
0x0000010: b800 47b6 004d b900 5201 002b b900 5401
0x0000020: 0059 1256 b800 472b b900 4201 0059 1244
0x0000030: b800 47b6 005a c000 …Run Code Online (Sandbox Code Playgroud) 我正在做
tvCartTotalAmount.setText("tk "+String.format("%.2f",totalAmount)+"/-");
Run Code Online (Sandbox Code Playgroud)
输出是
传统知识 315/-
我想表现得像
? 315/-
我怎样才能做到这一点?