Android 深度链接意图返回未解析的引用

Android 深度链接意图返回未解析的引用,android,android-studio,kotlin,deep-linking,Android,Android Studio,Kotlin,Deep Linking,我试图获取具有深度链接的类别中的帖子列表,但它返回未解析的引用 截图 文档 我的代码 错误 代码 class CategoryLinkDetails:Fragment(){ 私有lateinit var MINTERSTIALAD:中间层 私有lateinit var homeViewModel:homeViewModel 私有变量recyclerView:recyclerView?=null 覆盖创建视图( 充气机, 容器:视图组?, savedInstanceState:捆绑? ):查

我试图获取具有深度链接的类别中的帖子列表,但它返回
未解析的引用

截图
文档

我的代码

错误

代码
class CategoryLinkDetails:Fragment(){
私有lateinit var MINTERSTIALAD:中间层
私有lateinit var homeViewModel:homeViewModel
私有变量recyclerView:recyclerView?=null
覆盖创建视图(
充气机,
容器:视图组?,
savedInstanceState:捆绑?
):查看{
super.onCreate(savedInstanceState)
homeViewModel=ViewModelProviders.of(this.get)(homeViewModel::class.java)
val root=充气机。充气(R.layout.categorylink_详细信息,容器,false)
RecycleView=root.findViewById(R.id.categorylinkRecycle)
手册内容(意图)
返回根
}
//api代码
覆盖Wintent(意图:意图){
super.onNewIntent(意图)
手册内容(意图)
}
私人娱乐手册内容(意图:意图){
val appLinkAction=intent.action
val appLinkData:Uri?=intent.data
if(Intent.ACTION_VIEW==appLinkAction){
appLinkData?.lastPathSegment?.也{recipeId->
解析content://com.my.app/categories/")
.buildon()
.appendPath(recipeId)
.build()。同时{appData->
//实例化RequestQueue。
val queue=Volley.newRequestQueue(活动)
val url=”https://example.com/v1/categories/$recipeId“
//从提供的URL请求字符串响应。
val stringRequest=stringRequest(
Request.Method.GET,url,
Response.Listener{Response->
val jsonArray=jsonArray(响应)
val列表:ArrayList=ArrayList()
for(在0中输入i直到jsonArray.length()){
val jsonObject=jsonArray.getJSONObject(i)
添加(parseData(jsonObject))
}
//在这里,您将拥有“list”变量中的完整数据列表
categoriesRecycle.layoutManager=LinearLayoutManager(活动)
Log.d(“我的列表”,list.toString())
categoriesRecycle.adapter=MyCategorityListAdapter(列表)
},
Response.ErrorListener{error->
//如果发生错误,则在toast中显示错误
Toast.makeText(活动、错误消息、Toast.LENGTH\u SHORT)
.show()
})
//将请求添加到RequestQueue。
添加(stringRequest)
}
}
}
}
私有数据(jsonObject:jsonObject):MyCategoryLink{
var listingObject=MyCategoryLink(
jsonObject.getString(“名称”),
jsonObject.getString(“slug”),
HtmlCompat.fromHtml(jsonObject.getString(“body”)、HtmlCompat.FROM\uHTML\uMode\uCompact),
getString(“图像”)
)
返回列表对象
}
}
注:

我的代码和文档之间的唯一区别是我使用了
Fragment
,因为我需要显示一个帖子列表,但是在他们使用的文档中
Activity


有什么想法吗?

您需要在活动类中处理意图数据,然后需要将意图传递给片段构造函数 请参阅下面的代码

class TestActivity :AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    handleIntent(intent)
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    handleIntent(intent)
}

private fun handleIntent(intent: Intent?) {
    // now from here you can add your fragment here
    var categoryDetails = CategoryDetailsFragment(intent)
    var ft = supportFragmentManager.beginTransaction()
    ft.add(R.id.container,categoryDetails)
}}

我希望这会有所帮助。

那么你的意思是我应该制作另一个文件(活动)?然后在我的片段中调用那个活动?不。您将在您的活动中获得深层链接意图,您在androidmanifest.xml文件中提到过。在活动中,您将获得意图,然后您可以使用该意图获取数据或链接。获得deeplink url后,您可以根据您的deeplink url添加片段。希望你收到这个
class TestActivity :AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    handleIntent(intent)
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    handleIntent(intent)
}

private fun handleIntent(intent: Intent?) {
    // now from here you can add your fragment here
    var categoryDetails = CategoryDetailsFragment(intent)
    var ft = supportFragmentManager.beginTransaction()
    ft.add(R.id.container,categoryDetails)
}}