分享簡單的資料

2021-07-08 13:38:20 字數 3010 閱讀 2087

可以使用intent將見得資料分享懂啊社交網路中。比如新聞閱讀類應用,可以將將一條鏈結傳送其他社交網路中。使用intent反響簡答的資料,首先要將資料存到intent中,將動作設為action_send,然後設定資料型別。

intent sendintent = new intent();

sendintent.setaction(intent.action_send);

sendintent.putextra();

sendinten.settype();

startactvitiy(sendintent);

putextra接受兩個引數,第一引數表示資料的名字,從intent中取資料的時候用這個名字,第二個引數就是你想要傳遞的值。要將資料分享到其他應用,第乙個引數要使用系統系統的名稱,具體值可查詢intent原始碼或文件。應為其他應用取出資料時是按照這些名字取的,如果使用自定義的名字,其他應用無法取出有效資料。同樣,你的應用要從取出intent中的資料,也要用系統提供的名稱。

settype(),設定資料型別,具體型別可以檢視文件.

下面**展示分享一段文字內容

intent sendintent = new intent();

sendintent.setaction(intent.action_send);

sendintent.putextra(intent.extra_text,"hello,i am the text to send!");

sendintent.settype("text/plain");

startactivity(sendintent);

如果使用者安裝的應用能相應action_send動作,並且mime 型別匹配(「text/plain」),系統會啟動這個應用,如果有多個應用匹配,則彈出乙個列表工使用者選擇。

使用action_send_multiple傳送多條資料。假如要分享三張jpeg,mime型別設為"iamge/jpeg",如果有幾種不同型別的(android 支援的型別有jepg,png,gif等)mime 型別設為iamge/*.下面**展示分享三張

arraylist iamgeuris = new arraylist();

imageuris.add(imageuri1);

imageuris.add(imageuri2);

iamgeuris.add(imageuri3);

intent shareintent = new intent();

shareintent.setaction(intent.action_send_multiple);

shareintent.putparcelablearraylistextra(intent.extra_stream,imageuris);

shareintent.settype("image/*);

startactivity(shareintent)

我們可以將資料傳送到其他應用,也可一接受其他應用的資料。傳送資料資料使用intent,接收資料,就是接收intent,在傳送資料時,設定了intent的動作,資料型別,類別以及資料。但是我們無法直接獲取資料,先要獲取intent,在從intent中讀取資料。

我們並不知道其他應用會傳送什麼樣的intent,但是我們知道我們想要獲取的資料型別,我們能處理的資料型別以及響應的動作。我們可以設定條件,來過濾intent,只有符合我們條件的intent才能啟動我們的應用。android提供了intent filter(意圖過濾器)來實現過濾功能。

使用intent filter ,在androidmanifest.xml檔案中新增intent filter標籤即可,根據需要設定過濾器。很多應用既可以分享鏈結,也可分享,說明乙個應用可以有多個intent filter.

下面**設定兩個intent filter,乙個用來接收一張,乙個用來接受文字.

android:name=.mainactivity"

android:label="mainactiity">

android:name="android.intent.action.send" />

android:name="android.intent.category.default" />

android:mimetype="image/*" />

intent-filter>

android:name="android.intent.action.send" />

android:name="android.intent.category.default" />

android:mimetype="text/plain" />

intent-filter>

activity>

設定好intent filter後,每當有應用使用隱式intent時,系統會在查詢安裝應用的androidmanifest檔案中的intent filter,如果該intent能夠通過我們的intent filter。系統啟動應用。接下來該在我們的應用中處理intent中攜帶的資料。

在設定intent filter的activity中獲取傳過來的intent ,使用getintent(),即可獲取intent,在從intent中取出資料。

下面**處理獲取的intent

//獲取intent,

intent intent = getintent();

string action = intent.getaction();//intent的動作

string type = intent.gettype();//intent攜帶的資料型別

if (intent.action_send.equals(action) && type !=

null)else

if (type.startswith(

"image/"))

}

phaser 簡單分享

今天是先說一下具體的實現 其實這個用phaser 做h5 動畫其實最關鍵的是想好自己的幾個畫面,幾個畫面就對應幾個狀態,就要寫幾個js 檔案與之對應按照我的習慣行為就是以乙個index.html 頁面為乙個開始頁面,這個也面主要是引入一些必須的js庫檔案,設定橫螢幕還是豎螢幕,設定幾個狀態頁面等。一...

鏈結分享的簡單思考

鏈結分享可以說是乙個非常常用的功能了,本次網頁鏈結分享做一些簡單的探索 這樣就可以通過在鏈結預設新增 id作為跳轉鏈結了 分析 思路 既然有了賬號系統,並且頁面的內容是隨著使用者的操作而改變的,那麼我們可以將鏈結分為兩部分 頁面和操作,在使用者分享頁面時,將當前的操作行為記錄下來作為引數新增到鏈結中...

好文分享 簡單 快樂

我建立這個部落格,旨在感受一下極簡主義的生活方式所帶來的快樂和挑戰。我堅信,簡簡單單地生活可以更快樂。我想抓住 恰到好處 那令人難以捉摸的真 諦。同時,我也希望找乙個地方,讓我的志同道合者共同分享他們的酸甜苦辣,挫折抑或成功的點點滴滴。你也許會想,我不可能成為乙個極簡主義者 我養寵物 我帶著孩子 我...