添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

如何解决BadParcelableException问题

0 人关注

该代码不能在Pixel4的安卓13系统中运行,但它可以在其他手机中运行。

            Intent share_intent = new Intent();
            share_intent.setAction(Intent.ACTION_SEND);
            share_intent.setType("video/*");
            share_intent.putExtra(Intent.EXTRA_STREAM,fileUri);
            final PackageManager pm = m_activity.getPackageManager();
            List<ResolveInfo> resInfo = pm.queryIntentActivities(share_intent, 0);
            List<LabeledIntent> intentList = new ArrayList<>();
            for (int i = 0; i < resInfo.size(); i++) {
                ResolveInfo ri = resInfo.get(i);
                String packageName = ri.activityInfo.packageName;
                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("video/*");
                intent.putExtra(Intent.EXTRA_STREAM, fileUri);
                intent.putExtra(Intent.EXTRA_TITLE, "ttt00");
                CharSequence title = "123";
                intentList.add(new LabeledIntent(intent, packageName, title, ri.getIconResource()));
            Intent openInChooser = Intent.createChooser(intentList.remove(0), "Share");
            openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[intentList.size()]));
            m_activity.startActivityForResult(openInChooser,GameActivity.ActivityRequestCode.SHARE_VIDEO);

it will throw the exception

2022-05-26 20:22:35.144 1685-3668/? E/PackageManager: Package Manager Unexpected Exception
    android.os.BadParcelableException: Parcel data not fully consumed, unread size: 40
        at android.os.Parcel.enforceNoDataAvail(Parcel.java:929)
        at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2216)
        at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(PackageManagerService.java:7086)
        at android.os.Binder.execTransactInternal(Binder.java:1280)
        at android.os.Binder.execTransact(Binder.java:1244)
2022-05-26 20:22:35.146 29790-29790/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: android:ui, PID: 29790
    java.lang.RuntimeException: Unable to start activity ComponentInfo{android/com.android.internal.app.ChooserActivity}: android.os.BadParcelableException: Parcel data not fully consumed, unread size: 40
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3679)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3816)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:99)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2299)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7844)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)