導航:首頁 > APP軟體 > 安卓intent分享鏈接

安卓intent分享鏈接

發布時間:2023-08-03 23:28:07

㈠ android 調用系統分享怎樣分享一個鏈接

為了應用的推廣、傳播,很多的應用中都有「分享」功能,一個按鈕,點擊後會出現簡訊、微博等等一切實現了分享功能的應用列表。這一篇文章主要介紹怎麼調用分享功能和怎麼實現分享介面讓自己應用出現分享列表中。Android應用中能很方便的完成這些功能,這也正是Android的偉大之處,他能很簡單的完成應用之間的溝通以相互整合。

調用分享功能
1、分享文本
分享功能使用的隱式啟動Activity的方法,這里的Action使用的是 ACTION_SEND。
[java] view plainprint?在CODE上查看代碼片派生到我的代碼片
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

效果如下圖的圖一。
2、改變分享列表標題
使用上面的分享方式分享列表標題為「使用一下內容完成操作」,Android中提供了Intent.createChooser() ,這樣能一直顯示分享選擇列表,並且修改了分享列表標題內容。
[java] view plainprint?在CODE上查看代碼片派生到我的代碼片
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));

使用Intent.createChooser()的好處:
If you callIntent.createChooser() for the intent, Android will always display the chooser. This has some advantages:

Even if the user has previously selected a default action for this intent, the chooser will still be displayed.
If no applications match, Android displays a system message.
You can specify a title for the chooser dialog.

㈡ android怎麼把其他app的內容分享到自己的app里

很多時候我們的應用在使用微信分享內容之後,希望其他用戶點擊該分享內容能夠跳轉到我們的App,以實現閉環,這樣的分享才是最有價值的。這種需求涉及到不同應用之間的交互,雖然微信提供了分享SDK,但仍然有不少限制,現在總結兩種在Android平台上初步認為可行的方案:

1.分享網頁,從分享的網頁跳轉回原App。

2.分享WXAppExtendObject類型的數據,且只能分享給好友,好友從聊天列表點擊收到的分享內容可以直接跳轉第三方App(前提是好友手機上已經安裝了該App)。下面來詳細說明兩個方案,由於是在項目中實測的,為了隱私及行文方便,假設我們的應用的名字為MyApp,效果截圖也就不再展示。

方案一:

從WebView(該WebView從屬於另一個App,並非我們自己的App)跳轉到MyApp的某個界面(這里以跳轉到MyApp的Acticity A為例)。具體的實現邏輯如下:

(1)該WebView顯示的網頁內容只是一個超鏈接,自定義了一個scheme=myapp://,後邊可以附加一些參數,如果需要從網頁向App傳值的話。

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>This is title</title>

</head>

<body>

<a href=』myapp://id=909624′>Jump to MyApp</a>

</body>

</html>

該網頁在WebView打開後就是一個簡單的超鏈接,截圖不再附。

(2)MyApp中的Activity A需要配置特定的infliter,如下:

<activity

<intent-filter>

<data android:scheme="myapp" />

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

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

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

</intent-filter>

</activity>

(3)當在WebView上點擊上述自定義的超鏈接時就可以打開MyApp的A界面,所傳遞的參數也可以在所跳轉到的Activity中獲取,方法如下:

getIntent().getScheme();//獲得Scheme名稱

getIntent().getDataString();//獲得Uri全部路徑,根據自定義的格式解析字元串即可獲取我們上面附加的參數。可行的實施方案:

MyApp中調用微信分享分享網頁內容,只需要在網頁中嵌入跟Android客戶端約定好的超鏈接協議scheme,那麼點擊時就可以跳轉到MyApp。

問題1:如果用戶安裝了MyApp,就可以點擊網頁跳轉,如果沒有安裝MyApp的話,WebView就會提示找不到該頁面。製作網頁時可以在網頁中做檢測,沒安裝MyApp的話,頁面就重定向到應用的下載頁面。

問題2:在普通App的WebView中和瀏覽器中上述機制是可以的,但是在微信的WebView是不可以點擊直接跳轉我們的應用的,可能是微信做了某些過濾,且僅僅支持跟微信有深度合作的應用的跳轉,如大眾點評是可以的。針對這種情況,我們可以引導用戶使用瀏覽器打開所分享的網頁,然後點擊就可以跳轉應用了。方案二:

使用微信SDK分享WXAppExtendObject數據給好友,好友點擊跳轉MyApp的某個頁面(需要在分享時傳遞構造跳轉Intent的參數)。

1.該類型的分享(具體請參考微信分享SDK)可以帶幾個參數,參數中必須附帶一些構造跳轉Intent的數據。

2.好友點擊分享的內容,回調IWXAPIEventHandler介面的類的onReq方法,具體為

ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:這種情況才會調用,此時可以取出分享時附帶在參數中的一些數據,構造一個跳轉Intent,調用startActivity(intent) 來打開MyApp。

由於是項目實測,這種實現方式的截圖也就不傳了。

問題1:該分享方式只能分享給好友,不能分享到朋友圈。

問題2:如果好友沒安裝MyApp,點擊微信中好友分享過來的消息後無反應,無法提醒「未安裝MyApp,請下載」,因為這些邏輯要實現的話本身就是在MyApp裡面寫的,原本沒裝的話根本無法檢測。

問題3:WXAppExtendObject類型的分享,數據有大小限制,

extInfo(String)限制2KB;

fileData(byte[])供第三方使用的文件二進制數據,最大10M;

filePath:(String)Local directory of the file provided for applications,本身長度最大10KB,文件大小同上,不超過10M。以上就是Android平台好友點擊微信分享的內容後跳轉來源App的兩種實現方案,各有優點和局限性,請根據自身業務需求選擇合適的分享方式,由於未能附截圖說明,如有哪裡表述不清楚的,歡迎留言討論。

㈢ 如何在Android中調用瀏覽器打開網頁

安卓代碼中我們有時需要調用瀏覽器來打開相應的網頁,此時可以有以下幾種實現方式:
一:
調用默認瀏覽器

Intent intent = new Intent(); //Intent
intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("此處填鏈接"); intent.setData(content_url); startActivity(intent);

其他瀏覽器

Intent intent = new Intent(); //Intent
intent = new Intent(Intent.ACTION_VIEW,uri); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("此處填鏈接"); intent.setData(content_url); intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);
uc瀏覽器":"com.uc.browser", "com.uc.browser.ActivityUpdate「opera:"com.opera.mini.android", "com.opera.mini.android.Browser"qq瀏覽器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
二:

1、自定義一個簡單的WebView瀏覽器,設置下面屬性:

mWebView = (ProgressWebView) findViewById(R.id.baseweb_webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new WebViewClient());

2、指定需要打開的額網頁,在自定義的WebViewActivity中打開,如:

WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.hao123.com");

3、還可以查看相關的自定義WebView簡單瀏覽器的Demo,《WebView控制項實現的簡單瀏覽器效果》,以及對應的TeachCourse介紹怎麼使用

㈣ 用 微信的 android SDK 怎麼分享信息 到微信

  1. 微信官方SDK的分享方法。

    //圖片

    Bitmap bt=BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.erweima); final Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bt, null,null));

//分享到朋友

private void shareToFriend(Uri uri) {

Intent intent = new Intent();
ComponentName comp = new ComponentName("com.tencent.mm",
"com.tencent.mm.ui.tools.ShareImgUI");
intent.setComponent(comp);
intent.setAction("android.intent.action.SEND");
intent.setType("image/*");
//intent.setFlags(0x3000001);
intent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(intent);
}

  1. 調用分享文本的android 系統方法。

//分享文字
public void shareText(View view) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my Share text.");
shareIntent.setType("text/plain");

//設置分享列表的標題,並且每次都顯示分享列表
startActivity(Intent.createChooser(shareIntent, "分享到"));
}

//分享單張圖片
public void shareSingleImage(View view) {
String imagePath = Environment.getExternalStorageDirectory() + File.separator + "test.jpg";
//由文件得到uri
Uri imageUri = Uri.fromFile(new File(imagePath));
Log.d("share", "uri:" + imageUri); //輸出:file:///storage/emulated/0/test.jpg

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到"));
}

//分享多張圖片
public void shareMultipleImage(View view) {
ArrayList uriList = new ArrayList<>();

String path = Environment.getExternalStorageDirectory() + File.separator;
uriList.add(Uri.fromFile(new File(path+"australia_1.jpg")));
uriList.add(Uri.fromFile(new File(path+"australia_2.jpg")));
uriList.add(Uri.fromFile(new File(path+"australia_3.jpg")));

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到"));
}

㈤ 在安卓分享中,如何通過ACTION_SEND進行指定應用分享,比如我想指定微博,qq,微信,朋友圈,最好有代碼

//指定分享的應用(type)
private void initShareIntent(String type) {
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type) ) {
share.putExtra(Intent.EXTRA_SUBJECT, "subject");
share.putExtra(Intent.EXTRA_TEXT, "your text");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(myPath)) ); // Optional, just if you wanna share an image.
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found)
return;
startActivity(Intent.createChooser(share, "Select"));
}
}
//一些常用應用包名:
case ID_QQWEIBO:
initShareIntent("com.tencent.wblog");
break;
case ID_WEIXIN:
initShareIntent("com.tencent.mm");
break;
case ID_EVERNOTE:
initShareIntent("evernote");
break;
case ID_SINAWEIBO:
initShareIntent("com.sina.weibo");
break;
case ID_RENREN:
initShareIntent("renren");
break;
case ID_QQ:
initShareIntent("tencent.mobileqq");
break;

㈥ android app怎樣實現微信分享

使用微信SDK分享WXAppExtendObject數據給好友,好友點擊跳轉MyApp的某個頁面(需要在分享時傳遞構造跳轉Intent的參數)。

1.該類型的分享(具體請參考微信分享SDK)可以帶幾個參數,參數中必須附帶一些構造跳轉Intent的數據。

2.好友點擊分享的內容,回調IWXAPIEventHandler介面的類的onReq方法,具體為

ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:這種情況才會調用,此時可以取出分享時附帶在參數中的一些數據,構造一個跳轉Intent,調用startActivity(intent) 來打開MyApp。

由於是項目實測,這種實現方式的截圖也就不傳了。

問題1:該分享方式只能分享給好友,不能分享到朋友圈。

問題2:如果好友沒安裝MyApp,點擊微信中好友分享過來的消息後無反應,無法提醒「未安裝MyApp,請下載」,因為這些邏輯要實現的話本身就是在MyApp裡面寫的,原本沒裝的話根本無法檢測。

問題3:WXAppExtendObject類型的分享,數據有大小限制,

extInfo(String)限制2KB;

fileData(byte[])供第三方使用的文件二進制數據,最大10M;

filePath:(String)Local directory of the file provided for applications,本身長度最大10KB,文件大小同上,不超過10M。

㈦ android開發intent怎麼傳遞集合

1、Intent(意圖)主要是解決Android應用的各項組件之間的通訊。
2、為了實現傳遞數據這個目的需要以下步驟
3、Activity1需要構造一個 Intent,這個Intent用於告訴系統,我們要做「查看」動作
intent可調用putExtra來存放想要傳遞的數據
4、然後調用setClass,設置Activity1和欲調用的組件Activity2
5、最後調用startActivity將構造的Intent傳入,系統會根據此Intent中的描述,到Activity1中找到滿足此Intent要求的Activity,系統會調用找到的 Activity2最終傳入Intent在Activity2中可使用getIntent來獲取傳遞的Intent,並通過獲取數據的方法來獲取數據代碼示例:
Intent intent = new Intent(); // Activity1
intent.putExtra("one", num1);
intent.putExtra("two", num2);
intent.setClass(FirstActivity.this, SecondActivity.class);
startActivity(intent); Intent intent = getIntent(); //Activity2
String num1 = intent.getStringExtra("one");
String num2 = intent.getStringExtra("two");
int ret = Integer.parseInt(num1) + Integer.parseInt(num2);
result.setText(ret+"");
注意:在使用intent的時候可以使用bundle傳遞復制的數據類型。

閱讀全文

與安卓intent分享鏈接相關的資料

熱點內容
電信光貓要用超級賬戶密碼是什麼 瀏覽:73
冰法神器升級路線 瀏覽:795
汽車上的數據都有哪些 瀏覽:149
ipad怎麼刪除文件夾 瀏覽:649
感謝編程學校該怎麼說 瀏覽:217
怎麼給wps文件加密 瀏覽:528
美國有什麼購物網站 瀏覽:208
靈武品牌網路推廣有哪些 瀏覽:398
vhdl編程實例教程 瀏覽:336
微信找回密碼 瀏覽:782
怎麼撤回離線文件 瀏覽:380
unity3d教程pdf 瀏覽:149
三星2014升級怎麼辦 瀏覽:235
怎麼找到微信小視頻文件 瀏覽:278
求醫問葯的app 瀏覽:846
網路語大仲馬什麼意思 瀏覽:793
qq怎麼取消同城群 瀏覽:87
qq在流量不能發送文件 瀏覽:130
老闆直聘app下載怎麼注冊 瀏覽:413
哪裡查到各個國家確診數據 瀏覽:753

友情鏈接