If my app was started via ACTION_VIEW, how do I retrieve the attached data?

不想你离开。 提交于 2019-12-24 03:25:45

问题


I've made my app handle ACTION_VIEW intents for a certain data type, which it does fine. I can't seem to work out how to actually detect whether my app has been launched in this way though, and how to get at the attached data. Can someone point me in the right direction? Here's an excerpt from my manifest, if it helps.

<activity android:name=".MyApp"
          android:label="@string/app_name"
          android:screenOrientation="portrait" >

            ...

            <intent-filter>
              <action android:name="android.intent.action.VIEW"/>
              <action android:name="android.intent.action.EDIT" />
              <action android:name="android.intent.action.PICK" />
              <category android:name="android.intent.category.DEFAULT" />
              <data android:mimeType="audio/wav" />
            </intent-filter>


</activity>

回答1:


You can retrieve the data URI from the intent's data:

Uri uri = getIntent() != null ? getIntent().getData() : null;



回答2:


Detect if this action started your app by using:

    String action = intent.getAction();
    if ( Intent.ACTION_VIEW.equals( action ) // watch out for action being null!


来源:https://stackoverflow.com/questions/4648096/if-my-app-was-started-via-action-view-how-do-i-retrieve-the-attached-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!