Android實現(xiàn)調取支付寶健康碼
前言
調取支付寶健康碼,其實可以不使用接口去調用;我們可以通過倆個簡單的小功能去調取:
1.setOnClickListener事件,首先看源碼
/**
* Register a callback to be invoked when this view is clicked. If this view is not
* clickable, it becomes clickable.
*
* @param l The callback that will run
*
* @see #setClickable(boolean)
*/
public void setOnClickListener(@Nullable OnClickListener l) {
if (!isClickable()) {
setClickable(true);
}
getListenerInfo().mOnClickListener = l;
}在調用時傳入一個setOnClickListener對象作為參數(shù),該對象是一個接口類型的,源碼如下:
/**
* Interface definition for a callback to be invoked when a view is clicked.
*/
public interface OnClickListener {
/**
* Called when a view has been clicked.
*
* @param v The view that was clicked.
*/
void onClick(View v);
}我們可以使用匿名類型setOnclick去寫
2.Intent類
第一種構造函數(shù)指定類型:
Intent intent = new Intent(this,PersonActivity.class);
第二種SetClass方法指定類型:
Intent intent = new Intent();
intent.setClass(this,PersonActivity.class);
調用setComponent方法指定:
ntent intent = new Intent();
ComponentName component = new ComponentName(this,PersonActivity.class);
intent.setComponent(component);
我們這里用第一種方法就好了;
另外還有一些小知識點:Uri (代表要操作的數(shù)據(jù)),好了到這里就可以操作去寫代碼了;
</ String path ="client_type=2";
String link = URLEncoder.encode(path, "UTF-8");
String url = "alipays://platformapi/startapp?appId=2018062060350751&page=%2Fpages%2Fweb%2Fweb%3Furl%3Dhttps%3A%2F%2Fjsstm.jszwfw.gov.cn%2FjkmIndex.html";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);/>uri 里面填的就是在你手機運行打開健康碼的“地址”,
然后把他放進Uri這個類,用parse()方法去解析,
最后再把uri的值放到我們Intent類里面有倆個參數(shù)(Intent.ACTION_VIEW,我們解析好的變量uri)。
這樣我們就可以去使用它了,非常的方便,比在支付寶里找要方便很多,我這個提供的是江蘇的鏈接,其它鏈接可以百度,可能比較難百度,感興趣的小伙伴可以去試試吧!
總結
到此這篇關于Android實現(xiàn)調取支付寶健康碼的文章就介紹到這了,更多相關Android支付寶健康碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Android Studio和阿里云數(shù)據(jù)庫實現(xiàn)一個遠程聊天程序
本文主要介紹了Android Studio和阿里云數(shù)據(jù)庫實現(xiàn)一個遠程聊天程序,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
Android 廣播大全 Intent Action 事件詳解
這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識點,本文講解的非常的全面,感興趣的朋友一起看看吧2015-10-10
Android本地數(shù)據(jù)存儲Room實踐和優(yōu)化技巧
本文詳細介紹了Android本地數(shù)據(jù)存儲框架Room的使用,包括基本概念、核心組件、最佳實踐、優(yōu)化技巧等,幫助開發(fā)者學習和掌握Room的使用方法,提升數(shù)據(jù)存儲效率和應用性能2023-04-04

