強力なスキーム「android-app://」でサイト内リンクのクリックからIntentを自在に投げる

例えば, YouTubeのURLがあって,

http://www.youtube.com/watch?v=dQw4w9WgXcQ

WEBブラウザ向けにリンクを貼る場合

<a href="http://www.youtube.com/watch?v=dQw4w9WgXcQ">→ Go Movie</a>

と書く.

→ Go Movie

Android端末上では, これをクリックするとデフォルトのアプリ設定がされてない場合は暗黙的インテントが発行されて,

1. 該当アプリ選択ダイアログ

のあと,

2-a. ブラウザでYouTubeサイトの動画が表示される.
2-b. YouTubeアプリで動画が表示される.

となる.

ブラウザアプリとYouTubeアプリをインストールはほとんどの人ががインストールしているだろう.

20151015-083102

20151015-083210

そのリンク記述を

android-app://{package_id}[/{scheme}[/{host}[/{path}]]][#Intent;{...}]

の書式で書く. 書式内 {package_id} は必須.

<a href="android-app://com.google.android.youtube/http/www.youtube.com/watch?v=dQw4w9WgXcQ">→ Go Movie from android-app</a>

これをクリックすると, YouTubeアプリに対して明示的インテントが発行されて, 該当する動画が表示される.

→ Go Movie from android-app

これは以下をセットした明示的インテントを投げるのと等価.

Action:	 ACTION_VIEW
Data:    http://www.youtube.com/watch?v=dQw4w9WgXcQ
Package: com.google.android.youtube

もし YouTube アプリをインストールしていない場合は PlayStoreアプリが起動してYouTubeアプリの画面が表示されてそのままインストールすることができる.

20151015-084402

この書式を使うと

「該当アプリの選択」
「アプリのデフォルトの設定のクリア」

というユーザからみて煩わしい動作がなくなる上, 明示的インテントの

「該当するパッケージがみつからない」

という場合に対しての開発側の手間も省ける.

書式にあるようにこんな記述も可能.

<a href="android-app://com.example.app/
  #Intent;action=com.example.MY_ACTION;
  i.some_int=100;S.some_str=hello;end">...

これは以下明示的インンテントと等価.

Action:	 com.example.MY_ACTION
Package: com.example.app
Extras:	 some_int=(int)100
         some_str=(String)hello

便利だが, いつからこんなのあったんだ?

スキームはスキームなのかっ!?

注意: ブラウザ互換

Intent | Android Developers

Cross Reference: ../Intent.java


Google I/O を ウィジェットで見てみよう 見せてみよう

「I/O Live Embed Widget」なるものが公開されています.

I_O_Live_Embed_Widget 2

ブラウザ上で埋め込みHTMLを作成できます.

I_O_Live_Embed_Widget

埋め込んだ結果が以下.

埋め込んでみたかっただけです.

I/O Live Embed Widget


Google Earth プラグイン は いまどき使えないのか

もうネットの上で調べてもいろんな時期の情報があって混乱して困りますが.

何回インストールしてもこのざま.

Google_Earth

「NPAPIを有効化すればいける」というのは今ではもう古い話なのか.

64-bit Chrome drops support for Google Earth Plugin - Google Earth Blog

結局, 大筋はこういう予定らしく, 消える運命なNPAPI.

April 2015

In April 2015 (Chrome 42) NPAPI support will be disabled by default in Chrome and we will unpublish extensions requiring NPAPI plugins from the Chrome Web Store. All NPAPI plugins will appear as if they are not installed, as they will not appear in the navigator.plugins list nor will they be instantiated (even as a placeholder). Although plugin vendors are working hard to move to alternate technologies, a small number of users still rely on plugins that haven’t completed the transition yet. We will provide an override for advanced users (via chrome://flags/#enable-npapi) and enterprises (via Enterprise Policy) to temporarily re-enable NPAPI (via the page action UI) while they wait for mission-critical plugins to make the transition. In addition, setting any of the plugin Enterprise policies (e.g. EnabledPlugins, PluginsAllowedForUrls) will temporarily re-enable NPAPI.

September 2015

In September 2015 (Chrome 45) we will remove the override and NPAPI support will be permanently removed from Chrome. Installed extensions that require NPAPI plugins will no longer be able to load those plugins.

NPAPI deprecation: developer guide - The Chromium Projects

まだ, 猶予期間なので使うとすれば以下が必要要件と.

For the duration of the deprecation period, the set of supported browsers is as follows. Because of the recent Chrome and Firefox announcements, support on those browsers extends only to the latest browser version that supports NPAPI.

Microsoft Windows (XP, Vista, 7, and 8)
Google Chrome 5.0-39.0 (32-bit)
Internet Explorer 7-9, and 10-11 with Compatibility View (32-bit) (Note that the Windows 8 browsing mode with Internet Explorer does not support plugins.)
Firefox 11.0-34.0

Apple Mac OS X 10.6 or later (any Intel Mac)
Google Chrome 5.0-39.0 (32-bit)
Safari 3.1+
Firefox 11.0-34

Google Geo Developers Blog: Announcing deprecation of the Google Earth API

これって, もう 動かないってことで良いのですよね, フツーのユーザーからしたら.