2

将此应用程序用作框架并尝试将对象传递给我自己的 UI Phone Call 。

但是当我尝试将我的对象放入myAdapter

Call.putExtra("itemObject", items.get(position));

我收到一个BadParcelableException错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.server.telecom/com.android.server.telecom.components.UserCallActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.aliton.customphonecall.itemObject

问题:如何将我的对象传递给CallActivity

为了让它更清楚一点,我想通过Buttonin传递我的对象myAdapter

如下所示,Button轨道首先从myAdapterCallService内部CallService被称为CallActivity

然后我想我可以将我的对象传递给CallService并再次将我的对象传递给CallActivity.

I/debinf Adapter: Requesting Call
I/debinf CallService: onCallAdded
I/debinf OngoingCall: call.getState() is 9
I/debinf CallService: starting CallActivity
I/debinf CallActivity: onCreate
I/debinf OngoingCall: state is 1
I/debinf OngoingCall: state is 4

这里是myAdapter

public class myAdapter extends BaseAdapter {

    private ArrayList<itemObject> items;
    private Context context;

    public myAdapter(ArrayList<itemObject> items, Context context) {
        this.items = items;
        this.context = context;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_call, parent, false);

        TextView mName = (TextView) view.findViewById(R.id.item_name);
        TextView mId = (TextView) view.findViewById(R.id.item_id);
        final TextView mPhone = (TextView) view.findViewById(R.id.item_phone);
        ImageButton mCall = (ImageButton) view.findViewById(R.id.item_call);

        mName.setText(items.get(position).getName());
        mId.setText(items.get(position).getId());
        mPhone.setText(items.get(position).getPhone());

        mCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("tel:"+mPhone.getText().toString().trim());
                Intent Call = new Intent(Intent.ACTION_CALL, uri);
                Call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Call.putExtra("itemObject", items.get(position));
                Log.i("debinf Adapter", "Requesting Call");
                context.startActivity(Call);
            }
        });

        return view;
    }
}

这是我的CallService

public class CallService extends InCallService {

    @Override
    public void onCallAdded(Call call) {
        super.onCallAdded(call);

        Log.i("debinf CallService", "onCallAdded");
        new OngoingCallObject().setCall(call);

        Log.i("debinf CallService", "starting CallActivity");
        Intent CallAct = new Intent(this, CallActivity.class);
        CallAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CallAct.setData(call.getDetails().getHandle());
        startActivity(CallAct);

        //CallActivity.start(this, call);
    }

    @Override
    public void onCallRemoved(Call call) {
        super.onCallRemoved(call);
        Log.i("debinf CallService", "onCallRemoved");
        new OngoingCallObject().setCall(null);
    }

}

我想用我的对象来填充TextView左上角的CallActivity

电话呼叫2

这是DialerAcitivity图像。

电话呼叫1

我很感激任何帮助。

4

1 回答 1

0

对不起,但我有一个正确的答案,但这不是你所期望的。将自定义参数传递给 Intent.ACTION_CALL 并非不可能,因为对电话应用程序的真正调用是由忽略所有自定义参数的系统创建的(在 Intent.ACTION_CALL 调用中额外)。

于 2021-08-24T15:03:43.193 回答