'android studio mcpack ,mcworld How to apply Minecraft
We are creating an app that opens Minecraft when you select Minecraft files. Minecraft opens, but fails to load the file. There is no problem with the file size or path, how can I hand it over to Minecraft?
It doesn't matter if it's Java or Kotlin, so please reply.
cursor?.use {
if (it.moveToFirst()) {
val displayName: String =
it.getString(it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) // 1
if (displayName.endsWith(".mcaddon") || displayName.endsWith(".mcworld") ||
displayName.endsWith(".mcpack")|| displayName.endsWith(".mctemplate")
) {
val file = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName)
val file = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName)
val fileURI = FileProvider.getUriForFile(
this,
applicationContext.packageName + ".provider",
file
)
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.type = "file/*"
intent.data = Uri.parse("minecraft://?import=${file.path}")
startActivity(intent)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(fileURI, "application/octet-stream")
intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(intent)
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.setDataAndType(Uri.fromFile(file), "*/*")
intent.type = "*/*"
intent.data = Uri.parse("minecraft://?Path="+file.path)
startActivity(intent)
} else {
Toast.makeText(
this,
getString(R.string.extension),
Toast.LENGTH_SHORT
).show()
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
