<activityandroid:name="ShareActivity"><!-- filter for sending text; accepts SENDTO action with sms URI schemes --><intent-filter><actionandroid:name="android.intent.action.SENDTO"/><categoryandroid:name="android.intent.category.DEFAULT"/><dataandroid:scheme="sms" /><dataandroid:scheme="smsto" /></intent-filter><!-- filter for sending text or images; accepts SEND action and text or image data --><intent-filter><actionandroid:name="android.intent.action.SEND"/><categoryandroid:name="android.intent.category.DEFAULT"/><dataandroid:mimeType="image/*"/><dataandroid:mimeType="text/plain"/></intent-filter></activity>
之后,可以在当前Activity中接收附加的信息:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();
// Figure out what to do based on the intent type
if (intent.getType().indexOf("image/") != -1) {
// Handle intents with image data ...
} elseif (intent.getType().equals("text/plain")) {
// Handle intents with text ...
}
}
并且可以在给其他APP返回一个值:
// Create intent to deliver some kind of result data
Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri");
setResult(Activity.RESULT_OK, result);
finish();
//或者只返回一个标识符
setResult(RESULT_COLOR_RED);
finish();