开发者

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

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 mani开发者_高级运维fest, 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>


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

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


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!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜