开发者

How to deliver to different activity using ACTION_VIEW

开发者 https://www.devze.com 2023-03-30 01:00 出处:网络
<activity android:name=\".AnotherActivity\"> <intent-filter > <action android:name=\"android.intent.action.GET_CONTENT\" />
    <activity android:name=".AnotherActivity">
        <intent-filter >
            <action android:name="android.intent.action.GET_CONTENT" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.dir/vnd.google.note1" />
        </intent-filter>
    </activity>

    <activity android:name=".ThirdActivity">
        <intent-filter >
            <action android:name="android.intent.action.CHOOSER" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.dir/vnd.google.note2" />
        </intent-filter>
    </activity>`

This is my AndroidManifest.xml in a android project demo. I am using ContentProvider to deliver request to different activity. Delivering way is like this:

private OnClickListener l = new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        startActivity(intent);
    }
};
private Intent in开发者_如何学Ctent;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);
    Button btn = (Button)findViewById(R.id.button1);
    btn.setOnClickListener(l);
    intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("content://com.test/b"));
}

My question is how do i differ the two activities when i startActivity.

The only method i have thought is, make the two activty having different mimeTypes in AndroidManifest. And send request using different uri, and override getType method in provider to return respective mimetype for the two activity.


There are several ways to determine which activity handles your Intent. Depending on what you are trying to do, you may just want to set the class to directly choose which activity should be triggered. E.g.

Intent intent = new Intent(this, ThirdActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("content://com.test/b"));
0

精彩评论

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

关注公众号