Codeandroidmeetup3 Presentation 090727194330 Phpapp01

download Codeandroidmeetup3 Presentation 090727194330 Phpapp01

of 18

Transcript of Codeandroidmeetup3 Presentation 090727194330 Phpapp01

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    1/18

    Intents &

    Intent Filterscodeandroid.org

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    2/18

    Intents & Intents Filter

    Intents : request for an action to beperformed (usually on a set of data)

    Intent Filters : register Activities, Services,and Broadcast Receivers (as being capable

    of performing an action on a set of data) Broadcast Receivers : listens to intents

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    3/18

    Intents

    Support interaction between any

    application components available on anAndroid device

    start a new Activity broadcast messages (broadcast intents)

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    4/18

    IntentsStarting a new Activity

    Intent intent = new Intent (......................);startActivity(intent);

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    5/18

    IntentsStarting a new Activity

    Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse(tel:93675359));

    startActivity(intent);

    Dial a number

    Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(http://codeandroid.org));

    startActivity(intent);

    Launch a website

    http://codeandroid.org/http://codeandroid.org/
  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    6/18

    IntentsStarting a new Activity

    Intent intent = new Intent (this, HelloWorld.class);

    startActivity(intent);

    Launch an Activity

    Intent intent = new Intent (this, HelloWorld.class);

    intent.putExtra(title,Hello codeandroid);startActivity(intent);

    Launch an Activity

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    7/18

    Intent Filters

    AndroidManifest.xml

    Intent intent = new Intent (this, HelloWorld.class);startActivity(intent);

    Launch Hello World

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    8/18

    Intent Filters

    Required for Intent resolution tomatch Intents to Activities, Services, orBroadcastReceivers

    Most Intent Filters are declared in

    AndroidManifest.xml of an application

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    9/18

    Intent Filters

    AndroidManifest.xml

    Intent intent = new Intent (org.codeandroid.intentstest.HelloWorld);startActivity(intent);

    Launch Hello World

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    10/18

    Intent Filters

    AndroidManifest.xml

    Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(http://androidium.org));startActivity(intent);

    Launch Hello World

    http://codeandroid.org/http://codeandroid.org/http://codeandroid.org/http://www.androidium.org/http://www.androidium.org/
  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    11/18

    Intent Filters

    AndroidManifest.xml

    http://www.androidium.org/http://www.androidium.org/http://www.androidium.org/
  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    12/18

    Intent Filters

    AndroidManifest.xml

    Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(codeandroid://));startActivity(intent);

    Launch Hello World

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    13/18

    IntentsLaunch the Android Market

    Uri marketUri = Uri.parse(http://market.android.com/search?q=pname:com.buuuk.buUuk)

    Intent intent = new Intent (Intent.ACTION_VIEW, marketUri);startActivity(intent);

    Uri marketUri = Uri.parse(market://search?q=pname:com.buuuk.buUuk)Intent intent = new Intent (Intent.ACTION_VIEW, marketUri);startActivity(intent);

    http://market.android.com/search?q=%5Bhttp://market.android.com/search?q=%5Bhttp://market.android.com/search?q=%5Bhttp://market.android.com/search?q=%5B
  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    14/18

    IntentsBroadcast Intents

    broadcast messages betweencomponents with the sendBroadcastmethod

    makes an application more open, bybroadcasting to current and otherapplications

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    15/18

    IntentsBroadcast Intents

    Intent intent = newIntent(org.codeandroid.intentstest.TestBroadcastReceiver);sendBroadcast(intent);

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    16/18

    Broadcast Receivers

    listen to Broadcast Intents must be registered (either in code or

    within the app manifest

    use Intent Filter to specify whichIntents it is listening for

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    17/18

    Broadcast Receiversregistered inside code

    IntentFilter filter = new IntentFilter(org.codeandroid.intentstest.TestBroadcastReceiver);TestBroadcastReceiver receiver = new TestBroadcastReceiver();

    registerReceiver(receiver, filter);

    public class TestBroadcastReceiverextends Broadcast Receiver{

    @Overridepublic void onReceive(Context context, Intent intent){

    (.................... do something here................)

    }

    }

  • 8/13/2019 Codeandroidmeetup3 Presentation 090727194330 Phpapp01

    18/18

    Broadcast Receiversregister in app manifest

    public class CameraPressed extends Broadcast Receiver{@Overridepublic void onReceive(Context context, Intent intent){

    (.................... do something here................)

    }

    }