2014年1月30日 星期四

Android 開發 (二十一) 使用 URL開啟app

假設我們寫了一個很龐大的app裡面有很多功能,
然後今天來了一個使用者,他希望找到我們app裡的某個功能,
我們當然不可能直接前去指導那個使用者如何使用
這時我們可以使用 intent-filter 使我們的app導向特定頁面

又或者我在FB粉絲團留言中只提供簡略的描述,
當使用者點擊網址我希望能利用網址導向app的詳細頁面。

要實做這個功能就必須使用 intent-filter



 <activity
            android:name="com.example.intentfiltersample.MainActivity"
            android:label="@string/app_name" >
            <intent-filter android:priority="0">
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                   android:path="com.*"
                    android:scheme="http" >
                </data>
            </intent-filter>
        </activity>

這樣只需要在facebook上 貼文   http://com.functionA   http://com.functionB  並點擊
這樣就可以導向不同的功能頁面

接著只需要在接到時 getIntent().getDataString();  就可以取得網址了
附上 sample Code

沒有留言:

張貼留言