Search code examples
javaandroidandroid-intentintentfilter

issue with getIntent()


i need to open XML file with app that i am developing...the code is:

<intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file"  android:host="*" android:pathPattern=".*\\.xml"  android:mimeType="*/*"  />
        </intent-filter>

and it is ok!

but i need, when i click on file, to get data from xml file. In fragment if i write:

Intent intent = getIntent();
intent.getData().toString();

getIntent() is written in red by IDE...why?


Solution

  • If you're calling getIntent() from a Fragment you need to get the Activity on which it's running. So try

    Intent intent = getActivity().getIntent();

    Hope it helps