我需要显示比切片可以显示的更多的数据,所以我使用了 setSeeMoreAction(PendingIntent intent) 方法,它在切片末尾添加了“查看更多”功能,我们可以在点击它时设置要调用的动作待定意图。
在切片查看器应用程序上测试我的切片时,我可以看到“显示更多”功能并单击按预期工作,但是当我使用“应用程序操作测试工具”对其进行测试时,它没有显示“查看更多”负担能力。相反,有时(虽然有时没有显示)它会显示一个“打开应用程序”按钮,单击该按钮不会触发我在 setSeeMoreAction 中提到的未决意图,而是触发 RowBuilder 的 setPrimaryAction() 中提到的 SliceAction。
这是我的代码:
    override fun onBindSlice(sliceUri: Uri): Slice? {
    if(!isLoggedIn())  // if user is not logged in
    {
        return createLoginSlice(sliceUri).build()
    }
    var head = ListBuilder.HeaderBuilder()
            .setTitle("Slice Title")
    var slice = ListBuilder(context,sliceUri,ListBuilder.INFINITY)
            .setSeeMoreAction(orderActivityPendingIntent())
            .setHeader(head)
    for(i in 0 .. 6) {
            icon = IconCompat.createWithResource(context.applicationContext, R.drawable.placeholder)
        var row = ListBuilder.RowBuilder()
                .setTitleItem(icon!!,ListBuilder.LARGE_IMAGE,true)
                .setTitle(orderName.get(i),true)
                .setSubtitle(orderStatus.get(i),true)
                .addEndItem(IconCompat.createWithResource(context, colorScheme.get(i)),ListBuilder.SMALL_IMAGE)
                .setPrimaryAction(openOrderActivity(orderId.get(i)))
        slice.addRow(row)
    }
    return slice.build()
}
@RequiresApi(Build.VERSION_CODES.KITKAT)
private fun openOrderActivity(orderNo: String?): SliceAction {
    val intent = Intent(Intent.ACTION_VIEW, 
    Uri.parse(context.getString(R.string.orderURI)+orderNo))
        return SliceAction.create(
                PendingIntent.getActivity(context, 0, intent, 0),
                IconCompat.createWithResource(context, R.drawable.abc_ic_star_black_36dp),
                ListBuilder.ICON_IMAGE,
                "Open Order Activity."
        )
    }
private fun orderActivityPendingIntent(): PendingIntent {
        // create intent for order page here
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.orderPageURI)))
        return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
    }