Android-intents-filters
Android-インテントとフィルター
Android Intent は、実行される操作の抽象的な説明です。 startActivity を使用してActivityを起動し、 broadcastIntent を使用して関連するBroadcastReceiverコンポーネントに送信し、* startService(Intent)または bindService(Intent、ServiceConnection、int)*を使用してバックグラウンドサービスと通信できます。
'_* Intent自体、Intentオブジェクトは、実行される操作の抽象的な説明を保持するパッシブデータ構造です。*_
たとえば、メールクライアントを起動し、Androidデバイスを使用してメールを送信する必要があるアクティビティがあるとします。 この目的のために、アクティビティはACTION_SENDと適切な chooser をAndroid Intent Resolverに送信します。 指定されたセレクターは、ユーザーが電子メールデータを送信する方法を選択するための適切なインターフェイスを提供します。
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
startActivity(Intent.createChooser(email, "Choose an email client from..."));
上記の構文はstartActivityメソッドを呼び出して電子メールアクティビティを開始し、結果は次のようになります-
たとえば、AndroidデバイスのWebブラウザーでURLを開く必要があるアクティビティがあるとします。 この目的のために、アクティビティはACTION_WEB_SEARCH IntentをAndroid Intent Resolverに送信して、指定されたURLをWebブラウザーで開きます。 Intent Resolverはアクティビティのリストを解析し、Intentに最適なもの(この場合はWebブラウザアクティビティ)を選択します。 次に、Intent ResolverはWebページをWebブラウザに渡し、Webブラウザアクティビティを開始します。
String q = "finddevguides";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);
上記の例は、Android検索エンジンで finddevguides として検索し、アクティビティのfinddevguidesの結果を提供します
アクティビティ、サービス、ブロードキャストレシーバなど、コンポーネントの各タイプにインテントを配信するための個別のメカニズムがあります。
Sr.No | Method & Description |
---|---|
1 |
Context.startActivity() Intentオブジェクトはこのメソッドに渡され、新しいアクティビティを起動するか、既存のアクティビティを取得して新しいことを行います。 |
2 |
Context.startService() Intentオブジェクトはこのメソッドに渡され、サービスを開始したり、進行中のサービスに新しい指示を配信したりします。 |
3 |
Context.sendBroadcast() Intentオブジェクトはこのメソッドに渡され、関心のあるすべてのブロードキャストレシーバーにメッセージを配信します。 |
インテントオブジェクト
Intentオブジェクトは、Androidシステムで使用される情報と同様に、インテントを受け取るコンポーネントで使用される情報の束です。
Intentオブジェクトには、通信または実行しようとしている内容に基づいて、次のコンポーネントを含めることができます-
アクション
これはIntentオブジェクトの必須部分であり、実行するアクションの名前を示す文字列です。または、ブロードキャストインテントの場合、実行されて報告されているアクションです。 アクションは、主にインテントオブジェクトの残りの構造を決定します。 Intentクラスは、さまざまなインテントに対応するいくつかのアクション定数を定義します。 リンクのリストは次のとおりです:/android/android_intent_standard_actions [Android Intent Standard Actions]
Intentオブジェクトのアクションは、setAction()メソッドで設定し、getAction()で読み取ることができます。
Data
データ仕様をインテントフィルターに追加します。 仕様は、単なるデータ型(mimeType属性)、単なるURI、またはデータ型とURIの両方にすることができます。 URIは、その各部分の個別の属性によって指定されます-
URL形式を指定するこれらの属性はオプションですが、相互に依存しています-
- インテントフィルターにスキームが指定されていない場合、他のすべてのURI属性は無視されます。 *フィルターにホストが指定されていない場合、ポート属性とすべてのパス属性は無視されます。
setData()メソッドはデータをURIとしてのみ指定し、setType()はデータをMIMEタイプとしてのみ指定し、setDataAndType()はデータをURIとMIMEタイプの両方として指定します。 URIはgetData()によって読み取られ、タイプはgetType()によって読み取られます。
アクション/データのペアのいくつかの例は-
Sr.No. | Action/Data Pair & Description |
---|---|
1 |
識別子が「1」である人に関する情報を表示します。 |
2 |
ACTION_DIAL content://contacts/people/1 記入済みの電話ダイヤラーを表示します。 |
3 |
ACTION_VIEW tel:123 指定された番号が入力された電話ダイヤラを表示します。 |
4 |
ACTION_DIAL tel:123 指定された番号が入力された電話ダイヤラを表示します。 |
5 |
ACTION_EDIT content://contacts/people/1 識別子が「1」の人物に関する情報を編集します。 |
6 |
ACTION_VIEW content://contacts/people/ ユーザーが閲覧できる人のリストを表示します。 |
7 |
ACTION_SET_WALLPAPER 壁紙を選択するための設定を表示する |
8 |
ACTION_SYNC 同期データになります、定数値は android.intent.action.SYNC です |
9 |
ACTION_SYSTEM_TUTORIAL プラットフォーム定義のチュートリアルを開始します(デフォルトのチュートリアルまたは起動チュートリアル) |
10 |
ACTION_TIMEZONE_CHANGED タイムゾーンが変更されたときに推測します |
11 |
ACTION_UNINSTALL_PACKAGE デフォルトのアンインストーラーを実行するために使用されます |
カテゴリー
カテゴリはIntentオブジェクトのオプション部分であり、インテントを処理するコンポーネントの種類に関する追加情報を含む文字列です。 addCategory()メソッドはIntentオブジェクトにカテゴリを配置し、removeCategory()は以前に追加されたカテゴリを削除し、getCategories()は現在オブジェクトにあるすべてのカテゴリのセットを取得します。 こちらがlink:/android/android_intent_standard_categories [Android Intent Standard Categories]のリストです。
以下のセクションのインテントフィルタの詳細を確認して、カテゴリを使用してインテントに対応する適切なアクティビティを選択する方法を理解してください。
補足
これは、インテントを処理するコンポーネントに配信される追加情報のキーと値のペアになります。 エキストラは、それぞれputExtras()およびgetExtras()メソッドを使用して設定および読み取ることができます。 リンクのリストは次のとおりです:/android/android_intent_standard_extra_data [Android Intent Standard Extra Data]
フラグ
これらのフラグはIntentオブジェクトのオプション部分であり、Androidシステムにアクティビティの起動方法、および起動後の処理方法などを指示します。
Sr.No | Flags & Description |
---|---|
1 |
FLAG_ACTIVITY_CLEAR_TASK Context.startActivity()に渡されたIntentで設定された場合、このフラグは、アクティビティが開始される前に、アクティビティに関連付けられている既存のタスクをクリアします。 つまり、アクティビティは空のタスクの新しいルートになり、古いアクティビティはすべて終了します。 これは、FLAG_ACTIVITY_NEW_TASKと組み合わせてのみ使用できます。 |
2 |
FLAG_ACTIVITY_CLEAR_TOP 設定されていて、起動されるアクティビティが現在のタスクで既に実行されている場合、そのアクティビティの新しいインスタンスを起動する代わりに、そのアクティビティの他のすべてのアクティビティが閉じられ、このインテントが(現在top)新しいインテントとしての古いアクティビティ。 |
3 |
FLAG_ACTIVITY_NEW_TASK このフラグは、通常、「ランチャー」スタイルの動作を表示するアクティビティで使用されます。実行可能なアクティビティのリストをユーザーに提供します。 |
コンポーネント名
このオプションのフィールドは、Activity、Service、またはBroadcastReceiverクラスのいずれかを表すandroid ComponentName オブジェクトです。 設定されている場合、Intentオブジェクトは指定されたクラスのインスタンスに配信されます。それ以外の場合、AndroidはIntentオブジェクト内の他の情報を使用して適切なターゲットを見つけます。
コンポーネント名はsetComponent()、setClass()、またはsetClassName()によって設定され、getComponent()によって読み取られます。
インテントの種類
Androidがサポートするインテントには次の2種類があります
明示的な意図
アプリケーションの内部世界に接続される明示的な意図、あるアクティビティを別のアクティビティに接続する場合、明示的な意図でこの引用を行うことができます。下の画像はボタンをクリックして最初のアクティビティを2番目のアクティビティに接続します。
これらのインテントは、名前によってターゲットコンポーネントを指定し、通常、下位サービスを開始するアクティビティや姉妹アクティビティを起動するアクティビティなど、アプリケーション内部のメッセージに使用されます。 たとえば-
//Explicit Intent by specifying its class name
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
//Starts TargetActivity
startActivity(i);
暗黙の意図
これらのインテントはターゲットに名前を付けず、コンポーネント名のフィールドは空白のままになります。 暗黙のインテントは、他のアプリケーションのコンポーネントをアクティブにするためによく使用されます。 たとえば-
Intent read1=new Intent();
read1.setAction(android.content.Intent.ACTION_VIEW);
read1.setData(ContactsContract.Contacts.CONTENT_URI);
startActivity(read1);
上記のコードは、次のように結果を返します
インテントを受け取るターゲットコンポーネントは、* getExtras()*メソッドを使用して、ソースコンポーネントによって送信された追加のデータを取得できます。 たとえば-
//Get bundle object at appropriate place in your code
Bundle extras = getIntent().getExtras();
//Extract data using passed keys
String value1 = extras.getString("Key1");
String value2 = extras.getString("Key2");
例
次の例は、さまざまなAndroid組み込みアプリケーションを起動するAndroid Intentの機能を示しています。
Step | Description |
---|---|
1 | You will use Android studio IDE to create an Android application and name it as My Application under a package com.example.saira_000.myapplication. |
2 | Modify src/main/java/MainActivity.java file and add the code to define two listeners corresponding two buttons ie. Start Browser and Start Phone. |
3 | Modify layout XML file res/layout/activity_main.xml to add three buttons in linear layout. |
4 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/com.example.My Application/MainActivity.java の内容です。
package com.example.saira_000.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
startActivity(i);
}
});
b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("tel:9510300000"));
startActivity(i);
}
});
}
}
以下は res/layout/activity_main.xml ファイルの内容です-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intent Example"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/imageButton"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Browser"
android:id="@+id/button"
android:layout_alignTop="@+id/editText"
android:layout_alignRight="@+id/textView1"
android:layout_alignEnd="@+id/textView1"
android:layout_alignLeft="@+id/imageButton"
android:layout_alignStart="@+id/imageButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Phone"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_alignRight="@+id/textView2"
android:layout_alignEnd="@+id/textView2"/>
</RelativeLayout>
以下は、2つの新しい定数を定義する res/values/strings.xml の内容です-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My Applicaiton</string>
</resources>
以下は、 AndroidManifest.xml のデフォルトのコンテンツです-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.saira_000.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
*My Application* アプリケーションを実行してみましょう。 環境設定中に *AVD* を作成したと思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルのいずれかを開き、ツールバーのRun image:/android/eclipse_run.jpg[Eclipse Run Icon]アイコンをクリックします。AndroidStudioは、アプリをAVDにインストールして起動し、すべてがセットアップとアプリケーションで問題ない場合、次のエミュレータウィンドウが表示されます-
今すぐ Start Browser ボタンをクリックすると、設定されたブラウザが起動し、以下に示すようにhttp://www.example.comが表示されます-
同様に、[電話を開始]ボタンを使用して電話インターフェイスを起動できます。これにより、既に指定された電話番号をダイヤルできます。
意図フィルター
別のアクティビティを呼び出すためにインテントがどのように使用されるかを見てきました。 Android OSはフィルターを使用して、指定された一連のアクション、カテゴリ、インテントに関連付けられたデータスキームの助けを借りてインテントを処理できるアクティビティ、サービス、およびブロードキャストレシーバーのセットを特定します。 マニフェストファイルで <intent-filter> 要素を使用して、アクティビティ、サービス、またはブロードキャストレシーバーに関連付けられたアクション、カテゴリ、およびデータ型を一覧表示します。
以下は、前述の2つのアクション、1つのカテゴリ、1つのデータのいずれかによって呼び出すことができるアクティビティ com.example.My Application.CustomActivity を指定する AndroidManifest.xml ファイルの一部の例です-
<activity android:name=".CustomActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="com.example.My Application.LAUNCH"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
上記のフィルターと一緒にこのアクティビティを定義すると、他のアクティビティは、 android.intent.action.VIEW を使用するか、カテゴリが提供された com.example.My Application.LAUNCH アクションを使用してこのアクティビティを呼び出すことができます。 android.intent.category.DEFAULT です。
*<data>* 要素は、呼び出されるアクティビティによって予期されるデータ型を指定します。上記の例では、カスタムアクティビティはデータが「http://」で始まることを予期しています
インテントが複数のアクティビティまたはサービスのフィルターを通過できる場合、ユーザーはどのコンポーネントをアクティブ化するかを尋ねられる場合があります。 ターゲットが見つからない場合、例外が発生します。
アクティビティを呼び出す前に、次のテストAndroidチェックがあります-
- フィルタ<intent-filter>は、上記のように複数のアクションをリストできますが、このリストを空にすることはできません。フィルタには少なくとも1つの<action>要素が含まれている必要があります。そうでない場合、すべてのインテントがブロックされます。 複数のアクションが言及されている場合、Androidはアクティビティを呼び出す前に言及されたアクションの1つと一致しようとします。
- フィルター<intent-filter>は、0、1、または複数のカテゴリーをリストできます。 言及されたカテゴリがない場合、Androidは常にこのテストに合格しますが、複数のカテゴリが言及された場合、カテゴリテストに合格するインテントについては、Intentオブジェクトのすべてのカテゴリがフィルタのカテゴリに一致する必要があります
- 各<data>要素は、URIとデータタイプ(MIMEメディアタイプ)を指定できます。 URIの各部分には、 scheme、host、port 、 path などの個別の属性があります。 URIとデータ型の両方を含むIntentオブジェクトは、その型がフィルターにリストされている型と一致する場合にのみ、テストのデータ型部分を渡します。
例
次の例は、上記の例の修正です。 ここでは、1つのインテントがで定義された2つのアクティビティを呼び出している場合にAndroidが競合を解決する方法を確認します。
Step | Description |
---|---|
1 | You will use android studio to create an Android application and name it as My Application under a package com.example.finddevguides7.myapplication;. |
2 | Modify src/Main/Java/MainActivity.java file and add the code to define three listeners corresponding to three buttons defined in layout file. |
3 | Add a new src/Main/Java/CustomActivity.java file to have one custom activity which will be invoked by different intents. |
4 | Modify layout XML file res/layout/activity_main.xml to add three buttons in linear layout. |
5 | Add one layout XML file res/layout/custom_view.xml to add a simple <TextView> to show the passed data through intent. |
6 | Modify AndroidManifest.xml to add <intent-filter> to define rules for your intent to invoke custom activity. |
7 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/MainActivity.java の内容です。
package com.example.finddevguides7.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1,b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
startActivity(i);
}
});
b2 = (Button)findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("com.example.
finddevguides7.myapplication.
LAUNCH",Uri.parse("http://www.example.com"));
startActivity(i);
}
});
b3 = (Button)findViewById(R.id.button3);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("com.example.
My Application.LAUNCH",
Uri.parse("https://www.example.com"));
startActivity(i);
}
});
}
}
以下は、変更されたメインアクティビティファイル src/com.example.My Application/CustomActivity.java の内容です。
package com.example.finddevguides7.myapplication;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
/**
*Created by finddevguides7 on 8/23/2016.
*/
public class CustomActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_view);
TextView label = (TextView) findViewById(R.id.show_data);
Uri url = getIntent().getData();
label.setText(url.toString());
}
}
以下は res/layout/activity_main.xml ファイルの内容です-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.finddevguides7.myapplication.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intent Example"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/imageButton"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Browser"
android:id="@+id/button"
android:layout_alignTop="@+id/editText"
android:layout_alignLeft="@+id/imageButton"
android:layout_alignStart="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start browsing with launch action"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_alignEnd="@+id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exceptional condition"
android:id="@+id/button3"
android:layout_below="@+id/button2"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2"
android:layout_toStartOf="@+id/editText"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
以下は res/layout/custom_view.xml ファイルの内容です-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/show_data"
android:layout_width="fill_parent"
android:layout_height="400dp"/>
</LinearLayout>
以下は、2つの新しい定数を定義する res/values/strings.xml の内容です-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My Application</string>
</resources>
以下は、 AndroidManifest.xml のデフォルトのコンテンツです-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.finddevguides7.myapplication">
<application
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:supportsRtl = "true"
android:theme = "@style/AppTheme">
<activity android:name = ".MainActivity">
<intent-filter>
<action android:name = "android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.example.finddevguides7.myapplication.CustomActivity">
<intent-filter>
<action android:name = "android.intent.action.VIEW"/>
<action android:name = "com.example.finddevguides7.myapplication.LAUNCH"/>
<category android:name = "android.intent.category.DEFAULT"/>
<data android:scheme = "http"/>
</intent-filter>
</activity>
</application>
</manifest>
*My Application* アプリケーションを実行してみましょう。 環境設定中に *AVD* を作成したと思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[画像を実行:/android/images/eclipse_run.jpg [Eclipse Run Icon]アイコンをクリックします。 Android StudioはAVDにアプリをインストールして起動し、セットアップとアプリケーションで問題がなければ、次のエミュレータウィンドウが表示されます-
では、最初のボタン「View Actionでブラウザを起動」から始めましょう。 ここでは、フィルター "android.intent.action.VIEW"を使用してカスタムアクティビティを定義しました。Webブラウザを起動しているAndroidによって定義されたVIEWアクションに対するデフォルトアクティビティがすでに1つあります。起動したい。
ブラウザを選択すると、AndroidはWebブラウザを起動してexample.com Webサイトを開きますが、IndentDemoオプションを選択すると、AndroidはCustomActivityを起動し、渡されたデータをキャプチャするだけで、次のようにテキストビューに表示されます-
ここで戻るボタンを使用して戻り、「起動アクションでブラウザを起動」ボタンをクリックします。ここで、Androidはフィルタを適用してアクティビティを定義し、カスタムアクティビティを起動します。
もう一度、戻るボタンを使用して戻り、「例外条件」ボタンをクリックします。ここで、Androidは指定されたインテントの有効なフィルターを見つけようとしますが、今回は https としてデータを使用しているため、定義された有効なアクティビティは見つかりません http の正しいアクションを与えているので、Androidは例外を発生させ、次の画面を表示します-