Intentについて
連絡先の2つの設定を表示します.
Intentのプロパティ設定:
1コードではactionは1つだけ機能し,categoryは複数機能する.
ジャンプ時、actionはcom.xc.demo.action、categoryは[hi,hello]
対応するxmlは次のように設定されています.
②Intentがdata属性を指定しない場合、type属性が機能します.そうしないとandroidシステムはdata属性値に基づいてデータのタイプを分析し、typeを指定する必要はありません.
③action,data,属性を同時に指定するとandroidは指定したデータ型に基づいて特定のアプリケーションを起動することができる.(コードは上記の通り)
④AndroidMinifest.xmlのでを設定した場合、categoryはデフォルト設定になりますが、明示的に書く必要があります.
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_GET_CONTENT);
- //
- intent.setType("vnd.android.cursor.item/phone");
- startActivityForResult(intent, PICK_CONTACT);
- Intent intent = new Intent();
- //String data = "http://www.baidu.com";
- String data = "content://contacts/people/";
- Uri uri = Uri.parse(data);
- intent.setAction(Intent.ACTION_VIEW);
- intent.setData(uri);
- startActivity(intent);
Intentのプロパティ設定:
1コードではactionは1つだけ機能し,categoryは複数機能する.
- Intent intent = new Intent();
- intent.setAction("com.xc.demo");
- intent.addCategory("hi");
- intent.addCategory("hello");
- intent.setAction("com.xc.demo.action");
- startActivity(intent);
ジャンプ時、actionはcom.xc.demo.action、categoryは[hi,hello]
対応するxmlは次のように設定されています.
- <intent-filter>
- <action android:name="com.xc.demo" /> // action , N
- <action android:name="com.xc.demo.action" />
- <category android:name="hi"/> //category ,
- <category android:name="hello"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
②Intentがdata属性を指定しない場合、type属性が機能します.そうしないとandroidシステムはdata属性値に基づいてデータのタイプを分析し、typeを指定する必要はありません.
③action,data,属性を同時に指定するとandroidは指定したデータ型に基づいて特定のアプリケーションを起動することができる.(コードは上記の通り)
④AndroidMinifest.xmlの