Android intent filter: associate app with file extension

后端 未结 16 2101
北海茫月
北海茫月 2020-11-22 11:06

I have a custom file type/extension that I want to associate my app with.

As far as I know, the data element is made for this purpose, but I can\'t get it working. h

16条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 11:54

    Read opening file in kotlin:

    private fun checkFileOpening(intent: Intent) {
        if (intent.action == Intent.ACTION_VIEW && (intent.scheme == ContentResolver.SCHEME_FILE
                        || intent.scheme == ContentResolver.SCHEME_CONTENT)) {
    
            val text = intent.data?.let {
                contentResolver.openInputStream(it)?.bufferedReader()?.use(BufferedReader::readText) 
            }
        }
    }
    

提交回复
热议问题