reading-notes

Intent Filters

Allowing Other Apps to Start Your Activity

  1. Action : Usually one of the platform-defined values such as ACTION_SEND or ACTION_VIEW.
  2. Data : A description of the data associated with the intent.
  3. Category : usually related to the user gesture or location from which it’s started ,all implicit intents are defined with CATEGORY_DEFAULT by default.

Handle the Intent in Your 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 ...
    } else if (intent.getType().equals("text/plain")) {
        // Handle intents with text ...
    }
}

Return a Result

// 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();