无法使用 AspectJ 为 Android 对话框创建方面

Can't create aspect for Android dialogs using AspectJ

我已经能够在视图上找到 OnClickListeners:

@After("execution(* android.widget.AdapterView.OnItemClickListener.onItemClick(..))")

以及活动中的事件:

@After("execution(* android.app.Activity.onResume(..))")

但出于某种原因,我似乎无法抓住 AlertDialog、Dialog 甚至 Dialog.Builder 中的任何内容。我想在显示对话框时随时添加建议。

没有成功:

@After("execution(* android...AlertDialog.show(..))")

没有成功:

@After("execution(* android.app.ProgressDialog.show(..))")

没有成功:

@After("execution(* *..DialogInterface+.*(..) || * *..Dialog+.*(..))")

我想如果我可以为视图和活动编写方面,我也可以为 AlertDialogs 做同样的事情。我仍然认为是我对 AspectJ 的有限了解阻碍了我在这里的运气?

问题是 Aspects 只能应用于您编写的代码。所以确实,它可以应用于您自己的 Activities 和 OnItemClickListener 实现,但是如果您不自己创建 Dialog 的子 class,它将使用用户设备上可用的 class,这将赢得应用您的建议。