我想知道如何禁用当用户点击状态栏中的通知时高亮效果,此外,我想让用户通过按钮按压直接与我放置在通知中的RemoteView进行交互。我知道这可以通过HTC Sense实现,在进行呼叫时会有一个正在进行的通知,已经实现了上述目标。请让我知道您是否有任何想法,具体而言,如何为嵌套在我的RemoteView中的视图设置OnClickListener?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/button"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Some Text" />
</LinearLayout>
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.yourlayout);
notification.contentView = contentView;
PendingIntent peClick = PendingIntent.getBroadcast(this, 0, new Intent("com.BUTTON_CLICK"), 0);
contentView.setOnClickPendingIntent(R.id.button, peClick);
PendingIntent peNothing = PendingIntent.getBroadcast(this, 0, new Intent("com.DO_NOTHING"), 0);
contentView.setOnClickPendingIntent(R.id.layout_root, peNothing);
顺便提一句,HTC 有能力以普通开发者无法做到的方式修改安卓系统,因此并不总是好的示范。
我仍在努力让一些类似的代码工作,但我目前的观察是不同版本的Android处理方式不同。在Ice Cream Sandwich上,在布局中为各个项使用setOnClickPendingIntent可以正常工作。然而,在早期版本的Android上,通知的contentIntent会首先触发,而按钮的意图永远不会触发。可能有某种方法可以解决这个问题,但我还没有找到。为通知的contentintent提供一个无用的意图似乎没有帮助,因为它仍然会捕获点击。