日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android:scheme 常用类型,android scheme

發布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android:scheme 常用类型,android scheme 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有時候我們開發的應用希望讓其他應用也可以訪問,Android平臺而言,可以通過Uri(統一資源標識符Uniform Resource Identifier)來實現.

Android中 URI的組成部分scheme, authority and path,其中authority又分為host和port。格式如下: scheme://host:port/path

舉個實際的例子:

content://com.dx.test:2020/folder/myfolder/dir

其中scheme 對應 content://

authority 對應 com.dx.test:2020

host 對應 com.dx.test

port 對應 2020

path 對應 /folder/myfolder/dir

這時候我們想到在mainifest.xml里面定義的activity標簽下的intent-filter子標簽data里面的各個屬性,實際上與上面是有對應關系的

android:mimeType="string"

android:path="string"

android:pathPattern="string"

android:pathPrefix="string"

android:port="string"

android:scheme="string" />

比如有在A應用程序的mainifest.xml中有這么個Activity

如上所示,在data里設置了 scheme和host,則該Activity可以接收和處理類似于 "sharetest://data/XXX"的鏈接。

在A應用程序的TestActivity中編寫處理Scheme的邏輯

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

/**

* Created by dengxuandeng on 16-3-9.

*/

public class TestActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.test_layout);

Intent a = getIntent();

Log.d("scheme", a.toString());

}

}

這里為了方便 直接用log打出來了.

到這里 A 程序就準備OK了.

在B應用程序中,可以直接寫一個函數 調起A引用程序中的這個TestActivity

public void gotoScheme(String url) {

Intent intent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(url));

Bundle bundle = new Bundle();

intent.putExtras(bundle);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

this.startActivity(intent);

}

調起的時候直接寫

gotoScheme("sharetest://data/123141")

那么使用B程序使用Scheme調起 A程序的TestActivity的時候,可以看到A程序的TestActivity打出來的log

03-09 11:35:48.126 1088-1088/com.dear.schemetest D/scheme: Intent { act=android.intent.action.VIEW dat=sharetest://data/123141 flg=0x24000000 cmp=com.dear.schemetest/.TestActivity (has extras) }

總結

以上是生活随笔為你收集整理的android:scheme 常用类型,android scheme的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。