如何解决Android Studio如何捕获关联文件
[Android studio]对不起,我在编码方面可悲。如何从我的应用程序捕获关联文件? 这是简单的txt文件。 我的尝试: 清单:
<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:scheme="content"/>
<data android:mimeType="text/plain"/>
<data android:scheme="file"/>
<data android:host="*" />
<data android:pathPattern=".*\\.txt"/>
</intent-filter>
关于创建活动的代码:
Intent intent=getIntent();
String filepath = "";
if(intent != null) {
String action=intent.getAction();
String type=intent.getType();
if(Intent.ACTION_VIEW.equals(action) && type.endsWith("txt")) {
Uri file_uri=intent.getData();
if(file_uri!=null)
filepath=file_uri.getPath();
else
filepath="No file";
} else if(Intent.ACTION_SEND.equals(action) && type.endsWith("txt")) {
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
filepath = uri.getPath();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。