我想共享/接收扩展名为“.wit”的文件,但我无法让它工作。
首先,我发送文件(一切正常)。
private fun createIntent(file: File) {
val fileUri: Uri = FileProvider.getUriForFile(context, FILE_PROVIDER, file)
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri)
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // Grant read permission
// You can add a subject and text to the sharing message if desired
shareIntent.putExtra(Intent.EXTRA_SUBJECT, file.name)
shareIntent.putExtra(Intent.EXTRA_TEXT, String.format(context.getString(R.string.workout_share_text), file.name))
// Start the share activity
context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_workout_content_description)))
}
companion object {
private const val SHARED_FILE_EXTENSION = ".wit"
private const val OUTPUT = "output"
private const val FILE_PROVIDER = "com.workout.intervaltimer.fileprovider"
}
然后我尝试接收该文件,这应该会导致打开我的应用程序,但没有。
<activity
android:name=".LauncherActivity"
android:exported="true"
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="work.out"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="text/plain" />
<data android:pathPattern=".*\\.wit" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
我做错了什么?看起来很简单。有想法吗?
尝试识别如下格式:
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\.yourextension" />
<data android:pathPattern=".*\\.yourextension" />
<data android:scheme="content" />
</intent-filter>
你还应该看看: