2016-04-28 45 views
1

我想讓用戶能夠與他人共享對象。
我有一個可以顯示與意圖過濾器這樣的對象信息的活動:Android:我如何分享鏈接並在用戶點擊此鏈接時打開活動

<intent-filter> 
    <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" android:host="www.mywebsite.com" /> 
</intent-filter> 

代碼共享:

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType("text/plain"); 
shareIntent.putExtra(Constants.EXTRA_OBJECT_ID, id); 
shareIntent.putExtra(Constants.EXTRA_IS_LOCAL, false); 
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.mywebsite.com"); 
startActivity(Intent.createChooser(shareIntent, "Share link using")); 

但是,當我點擊這個鏈接,我不能看到我的應用程序在「完成操作使用」對話框上。

回答

1

當前您嘗試發送/共享鏈接,但您在清單中添加了針對視圖的意圖過濾器。因此,對於視圖,您應該將意圖操作設置爲查看,然後嘗試。就像這樣:

Intent shareIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mywebsite.com")); 

這是因爲您已經添加視圖類別的意圖過濾器是:

<action android:name="android.intent.action.VIEW" /> 

如果你想分享的鏈接,然後在這樣的意圖過濾加送的類別:

<action android:name="android.intent.action.SEND"/> 

我認爲這對您會有幫助!

+0

我想先分​​享鏈接作爲文本,然後在用戶點擊此鏈接時打開活動 –