【发布时间】:2019-03-21 11:35:42
【问题描述】:
我想做什么:我在文件管理器中有 json 文件,我想点击他,然后必须在列表中显示应用程序选择器和我的应用程序才能使用。我想在 MyApp 中打开 json 文件并获取数据。
Json 没有默认应用来处理他。
实际上,我使用共享。我使用长按使工具可见并使用共享 -> MyApp。
AndroidManifest.xml
<activity android:name=".MyClassToDealWithJson">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/json" />
</intent-filter>
</activity>
MyClassToDealWithJson.class
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
uri = intent.getParcelableExtra(intent.EXTRA_STREAM);
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("*/*".equals(type)) {
//dealing with json
}
很难找到样本,或者我没有用正确的词搜索 :) 感谢您的帮助!
【问题讨论】:
-
我希望文件管理器使用
ACTION_VIEW,而不是ACTION_SEND。 -
对于共享 ACTION_VIEW 不起作用,只有 ACTION_SEND 可以正常工作。
标签: android json file android-manifest manifest