[英]flutter how to open txt file with open with dialog to specific page?
我是新手,没有使用Intent过滤器。 到目前为止,我的应用程序都可以正常工作了。 但我无法通过打开对话框将文件导入应用。 我需要用户,当它单击文件时,它将转到页面并在文件中显示信息。 我正在使用ImportFile插件,它工作正常,但使用户更难放置他们收到的文件。 我的应用程序是在“打开方式”对话框中列出的,但是当我单击它时,它只是打开该应用程序, 我希望它打开该应用程序并在查看文本页面(而非主页)中查看文本
AndroidManifest.xml <
intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:pathPattern="*.*\\.txt" />
</intent-filter>
MainActivity.java
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
先感谢您
FlutterView具有setInitialRoute方法,可用于在启动时指定非默认路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.