Search code examples
androidjsonfileandroid-manifestmanifest

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


What I want to do: I have json file in file manager, i want click on him, then must shown app chooser with my app on list to use. I want open json file in MyApp and get data.

Json dont have default app to deal with him.

Actually, I use sharing. I use long click to make tools visible and use share -> 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
        }

Its hard to find sample or i dont searching with right words :) Thanks for help!


Solution

  • Yeah, ACTION_VIEW works good. I just didnt run code code, because my Mainfest had red underline :)