æé»çã¤ã³ãã³ãã«è¨å®ããACTION_*
æé»çã¤ã³ãã³ããã¢ããªå é¨ããçºè¡ãããã¨ããã®ã¢ã¯ã·ã§ã³ã«å¯¾å¿ã§ããã¢ã¯ãã£ããã£ããã¤ã¢ããªãé¸æããã¦ããããä¸ã¤ã®å ´åã¯èµ·åãè¤æ°ã®å ´åã¯é¸æãã¤ã¢ãã°ã表示ãããã
ACTION_*ã®ç¨®é¡
- ACTION_CALL
- ACTION_VIEW
- ACTION_SEND
- ACTION_SET_WALLPAPER
- ACTION_WEB_SEARCH
ãªã©å¤æ°ã®ç¨®é¡ãããã
http://developer.android.com/intl/ja/reference/android/content/Intent.html
ã¡ã¼ã©ãèµ·åãããå ´å
Intent it = new Intent(); it.setAction(Intent.ACTION_SENDTO); it.setData(Uri.parse("mailto:[email protected]")); it.putExtra(Intent.EXTRA_SUBJECT, "ãµã³ãã«ã³ã¼ãã®ä»¶"); it.putExtra(intent.EXTRA_TEXT, "ããã¾ãã¦ããã§ã¨ããããã¾ãã"); startActivity(it);
ã¡ã¼ã©ããACTION_SENDTO ã«å¯¾å¿ã§ããã¢ã¯ãã£ããã£ããã£ã¦ããã°ããã®ã¡ã¼ã©ã¢ããªãèµ·åã¾ãã¯é¸æè¢ã®ä¸ã¤ã¨ãã¦è¡¨ç¤ºãããã
ãã©ã¦ã¶ãèµ·åãããå ´å
String text = inputText.getText().toString();
Uri url = Uri.parse(text);
Intent it = new Intent();
it.setAction(Intent.ACTION_VIEW);
it.setData(url);
startActivity(it);
ãã©ã¦ã¶ããACTION_VIEW ã«å¯¾å¿ã§ããã¢ã¯ãã£ããã£ããã£ã¦ããã°ããã®ãã©ã¦ã¶ã¢ããªãèµ·åã¾ãã¯é¸æè¢ã®ä¸ã¤ã¨ãã¦è¡¨ç¤ºãããã
èµ·åãããã¢ããªå´ã§ã¯ã©ããªè¨è¿°ãããã¦ãããã
ãããªãã¯ãACTION_VIEWãæé»çã¤ã³ãã³ãã§çºè¡ããããåå¿ããªãããã
ã¢ããªããçºè¡ããããæé»çã¤ã³ãã³ããã®ACTION_*ã®ç¨®é¡ã¯ãèµ·åããã(åãåã)ã¢ããªå ã§ã¯ã©ãè¨è¿°ããã¦ãããã
AndroidManifest.xml
<activity android:name=".ReceiveApplication" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter android:label="@string/app_name"> <action android:name="android.intent.action.SEND" /> <data android:mimeType="text/plain" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
ACTION_SENDã«å¯¾å¿ãã¦åå¿ããããã«è©²å½ã¢ã¯ãã£ããã£ã«ã¤ã³ãã³ããã£ã«ã¿ã¼ãè¨è¿°ãã¦ããã
ã¾ããåãåãã¤ã³ãã³ãã®ã¢ã¯ã·ã§ã³ä»¥å¤ã®æ
å ±
- Data
- Category
- Flags
- Extra
- Type
ã¯ãåå¿ãã/ããªãã«é¢ä¿ãã¦ããã®ã ããã
ã¾ãããã§ã«ã¤ã³ã¹ãã¼ã«ãã¦ããã¢ããªããããããã©ããªæé»çã¤ã³ãã³ãã«å¯¾ãã¦åå¿ããããã調ã¹ã¦ã¿ãããã¨ã
ã¤ã³ãã³ããã£ã«ã¿ã¼ã®è¨è¿°ã®ä¾
æã£ãããè¨è¿°ãè¤éãªæ°ãããã®ã§ãã©ããªè¨è¿°ããã¦ããã®ãéããã
http://www.techdoctranslator.com/android/guide/manifest/data-element
http://mindia.jp/book/dobby/keyword/Intent+Filter
ãã©ã¦ã¶ã®ããã¼ã¸ã®å ±æãããèµ·å
<action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" />
ãã©ã¦ã¶ã§ãªã³ã¯é·ç§»ãããã¨ããã¨ãã«èµ·å
<action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http" />
æ示çã¤ã³ãã³ãã»æé»çã¤ã³ãã³ãã®ä½¿ç¨ä¾
http://thinkit.jp/article/921/1/
ãIntent intent = new Intent(); ãintent.setAction(Intent.ACTION_SEND); ãintent.setType("image/jpeg"); ãintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("jpegãã¡ã¤ã«ã®å ´æ")); ãstartActivity(intent);
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/jpeg" /> </intent-filter>
éã«ãTwidroidãããããããããã¼ã®URLãéããã¨ãã«ãããããããã¼ã¢ããªãå¼ã°ãããããªä»çµã¿ãå®è£
ãã¦ãã¾ãã
http://mtl.recruit.co.jp/blog/2010/01/android.html
<activity android:name=".RwsHotpepperShopActivity" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" /> <data android:host="www.hotpepper.jp" /> <data android:pathPrefix="/str" /> </intent-filter> </activity>
http://lab.r246.jp/twicca/twicca_plugin.pdf
<intent-filter android:icon="@drawable/plugin_icon" android:label="@string/plugin_name"> <action android:name="jp.r246.twicca.ACTION_UPLOAD" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> â¦ç»åãã¢ãããã¼ãããå ´å <data android:mimeType="video/*" /> </intent-filter>
<intent-filter android:icon="@drawable/plugin_icon" android:label="@string/plugin_name"> <action android:name="jp.r246.twicca.ACTION_PLUGIN_SETTINGS" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
Quick Bookmark ã®ãã¨ãç¥ããªãã¢ããªããã§ãURLãä¿åãããå ´åã¯ããã©ã¦ã¶ãéãIntentã横åãããã°ããã¯ãã§ãã以ä¸ã Manifest ã«è¿½å ããã°ãhttp:// 㨠https:// ãéã Intent ã Activity ã«å±ãããã«ãªãã¾ãã <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="http" /> <data android:scheme="https" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> ãã ããã®ã¾ã¾ã ã¨ãURLããã¼ã¿ãã¼ã¹ã«ä¿åãã¦ããçµäºãã Activity ã§ãã£ã¦ããä¸ç¬ç»é¢ã«è¡¨ç¤ºããã¦ãã¾ãã¾ãããããé²ãããã«ãActivity ãéæåãã¾ãã <activity android:name=".AddActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar"> ãã¨ã¯ãActivity ã® onCreate() 㧠getIntent().getData().toString() ã㦠URL ãæååã¨ãã¦åãåºãã¦ãDBã«ä¿åãå³ finish() ã§çµäºã§ã
ããã㪠ACTION_* ãçºè¡ãã¦ã¿ã
ä¸ã®ã¢ã¯ã·ã§ã³ã®ç¨®é¡ä»¥å¤ã®æ å ±ã«é¢ãã¦ã¯ãç¡éãªãã¿ã¼ã³ãåå¨ãããã¨ã«ãªããããªã®ã§ãã¨ããããã¯ãã¢ã¯ã·ã§ã³ã®ç¨®é¡ã®ã¿ã§çºè¡ãã¦ã¿ãããã¨ã
ã¢ã¯ã·ã§ã³ã®ç¨®é¡ã®ã¿ã®çºè¡ã§ã¤ã³ã¹ãã¼ã«ããã¦ããã¢ã¯ãã£ããã£ã®åå¿ãã¿ãã¢ããªããã¼ã±ããã«ããã
http://jp.androlib.com/android.application.yanzm-example-getintentlist-AqtF.aspx
ãã®ä»ã®æ
å ±ã追å ãã¦ã®çºè¡ããã®åå¿ãã¿ãã¢ããªãããã
http://jp.androlib.com/android.application.com-codtech-android-intentplayground-qBq.aspx
ã³ãã³ãã©ã¤ã³ã§åå¿ãã¿ãã«ã¯ã
$ adb shell $ am usage: am [start|broadcast|instrument|profile] am start [-D] INTENT am broadcast INTENT am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>] [-w] <COMPONENT> am profile <PROCESS> [start <PROF_FILE>|stop] INTENT is described with: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] ...] [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...] [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...] [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...] [-n <COMPONENT>] [-f <FLAGS>] [<URI>]
ãªã®ã§
$ am start -a android.intent.action.VIEW http://www.google.com
ãã°ã®æ¸å¼ã確èªãã¦ã¿ãã
I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.threebanana.notes/.NoteEditor (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=jp.tomorrowkey.android.hatenabookmark/.PageInfoActivity (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.mgeek.android.DolphinBrowser.Browser/.PostToDelicious (has extras) } I/ActivityManager( 79): Starting activity: Intent { cmp=com.mgeek.android.DolphinBrowser.Browser/.ModifyDeliciousAccount } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.VIEW dat=http://www.google.com flg=0x10000000 cmp=android/com.android.internal.app.ResolverActivity } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.VIEW dat=http://www.google.com flg=0x10000000 cmp=android/com.android.internal.app.ResolverActivity } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://www.google.co.jp/ cmp=android/com.android.internal.app.ResolverActivity } I/ActivityManager( 79): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://www.google.co.jp/ flg=0x3800000 cmp=com.mgeek.android.DolphinBrowser.Browser/.BrowserActivity }
am start -a android.intent.action.VIEW http://www.google.com
am start -a android.intent.action.VIEW -t plain/text http://www.google.com x
am start -a android.intent.action.SEND http://www.google.com x
am start -a android.intent.action.SEND -t plain/text http://www.google.com
ã¤ã³ãã³ããã£ã«ã¿ã®è§£éã®ã«ã¼ã«
ç°¡åãªããã«è¦ããããè¤éã ã
- ã¹ãã¼ã ãæå®ãããåãæå®ããã¦ããªããã°ãã©ã®ãããªåã®Intentã¨ããããããã
- åãæå®ãããã¹ãã¼ã ãæå®ããã¦ããªããã°ãã©ã®ãããªã¹ãã¼ã ã®Intentã¨ããããããã
- ã¹ãã¼ã ãåãæå®ããã¦ããªããã°ãã¹ãã¼ã ãåãæå®ããã¦ããªãIntentã®ã¿ã¨ãããããã
- ãªã¼ã½ãªãã£ãæå®ããã¦ããã°ãã¹ãã¼ã ãæå®ããã¦ããªããã°ãªããªãã
- ãã¹ãæå®ããã¦ããã°ãã¹ãã¼ã ã¨ãªã¼ã½ãªãã£ãæå®ããã¦ããªããã°ãªããªãã