Android,点击 json 文件时从应用选择器中选择我的应用

Android, choose my app from app chooser when click on json file

我想做什么: 我在文件管理器中有 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 效果很好。我只是没有 运行 code 代码,因为我的 Manifest 有红色下划线:)