Android 如果指定了数据类型,则隐式意图找不到活动
我正试图制作一个使用隐式意图调用活动的示例。 我是根据这里所示示例的代码来做的Android 如果指定了数据类型,则隐式意图找不到活动,android,android-intent,Android,Android Intent,我正试图制作一个使用隐式意图调用活动的示例。 我是根据这里所示示例的代码来做的 getSecondActivity.setOnClickListener() { val gameNameStr = getTextFromView(gamerName) val gameStatusStr = getTextFromView(gameStatus) if (gameNameStr != null && gameStatus != nu
getSecondActivity.setOnClickListener() {
val gameNameStr = getTextFromView(gamerName)
val gameStatusStr = getTextFromView(gameStatus)
if (gameNameStr != null && gameStatus != null) {
val sendIntent = Intent().apply {
action = Intent.ACTION_VIEW
putExtra(GAMER_NAME, gameNameStr)
putExtra(GAME_STATUS, gameStatusStr)
type = "text/plain"
}
//Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(packageManager) != null) {
startActivity(sendIntent)
} else {
Toast.makeText(this@MainActivity, "No Activity", Toast.LENGTH_SHORT).show()
}
}
}
我在清单中指定了过滤器
<activity android:name=".ShowInfoFromFirst">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
启动时,将显示一条消息,表明未找到匹配的活动。如果我删除了类型,那么一切都正常。我在类Intent.java中遇到了一个描述
“类型--指定
意图数据。通常,类型是从数据本身推断出来的。
通过设置此属性,**可以禁用该评估并强制执行
“显式类型”
那么我不明白为什么这个例子对我不起作用