ต้อง utilise กล้องในแอพสำหรับการทำงานฉันเห็นทุกสิ่งทุกอย่างเปลี่ยนไปในรูปแบบ api>=28 เมื่อเทียบกับวิธีที่ฉันเคยต้องทำมันอยู่ไหนฉันสามารถใช้ startActivityForResult.
แต่ผมเผชิญหน้ากับปัญหาที่ฉันรถเรียกโปรแกรมกล้องแอพและทันทีได้'TransactionTooLargeException'ข้อความผิดพลาดในการดีบั๊ก/วิ่งคอนโซล.
สำหรับจากกล้องวงจรปิดกล้องฉันกำลังทำอะไร
mGetContent = registerForActivityResult(
new ActivityResultContracts.TakePicture(),
result -> {
if (result) {
}
}
);
อยู่ไหน mGetContent ถูกกำหนดในชั้นเรียนเป็น
private ActivityResultLauncher<Uri> mGetContent;
ในของฉัน AndroidManifest.xml แฟ้มฉันต้องต่อไปนี้
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
ในของฉัน file_paths ฉันมีแฟ้ม
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="."/>
<files-path
name="app_images"
path="./files/"/>
</paths>
ฉันมีปุ่มตั้งค่าภายในหอของกิจกรรมที่ฉันรถเรียกโปรแกรมกล้องใช้
findViewById(R.id.button)).setOnClickListener(v -> {
File directory = new File(context.getFilesDir(), "app_images");
if (!directory.exists()) directory.mkdir();
File file = new File(directory, "image.jpg");
Uri uri = getUriForFile(this, "com.test.fileprovider", file);
mGetContent.launch(uri);
};
ทันทีที่ดักฟังอยู่บนปุ่มและกล้องแอ๊ปเปิดขึ้นมาฉันจะได้ในสิ่งที่ฉันสามารถเดียวที่คิดคือการรู้สึกอินกับท่านนายพลเกิดข้อผิดพลาดข้อความไว้
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1284092)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test, PID: 14296
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:511)
at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4524)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
พยายามที่จะกูเกิ้ลเมื่อค้นหาอย่างแต่มีปัญหาฟังสิ่งที่แท้จริงประเด็น
มีคำแนะนำเล็งมาฉันตรงไปยัง onSaveInstanceState ดังนั้นฉันยกเลิกนั่นแล้ววางจุดหยุดอยู่เพื่อเห็นว่าเกิดอะไรขึ้นแต่มันจะผ่านมันมาโดยที่ไม่มีปัญหา(จากสิ่งที่ฉันสามารถบอก).
เป็นของที่สูญเสียกับเรื่องนี้