文章來源:https://blog.csdn.net/sunshine_0707/article/details/103313328
openinstall的作用:

第一步:登入openinstall官網,沒有賬號就注冊個
第二步:沒有應用就添加一個應用(選擇高級版)

第三步:下載導入sdk(其實就一個jar)
將下載的OpenInstall_v2.3.0.jar放入到libs文件夾下,然后在build.gradle下添加:
dependencies {
implementation files('libs/OpenInstall_v2.3.0.jar')
}
第四步:在AndroidManifest.xml中添加權限聲明
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
第五步:在AndroidManifest.xml的application標簽內設置AppKey
<meta-data
android:name="com.openinstall.APP_KEY"
android:value="******"/>
第六步:在application里添加初始化代碼
@Override
public void onCreate() {
super.onCreate();
if (isMainProcess()) {
openInstall();
}
}
//判斷是否是主進程
public boolean isMainProcess() {
int pid = android.os.Process.myPid();
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
return getApplicationInfo().packageName.equals(appProcess.processName);
}
}
return false;
}
第七步:在AndroidManifest.xml里指定自己的application
<application
android:name=".TestApplication"
/>
第八步:實現快速下載
如果只需要快速下載功能,無需其它功能(攜帶參數安裝、渠道統計、一鍵拉起),完成初始化即可
第九步:攜帶參數安裝,在application里添加以下代碼
private void openInstall() {
//初始化
OpenInstall.init(this);
//攜帶參數安裝
OpenInstall.getInstall(new AppInstallAdapter() {
@Override
public void onInstall(AppData appData) {
Log.d(TAG, "appData=" + appData);
//獲取渠道數據
channelCode = appData.getChannel();
//獲取自定義數據
try {
duanzishou = new JSONObject(appData.getData()).optString("duanzishou");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
第十步:測試攜帶參數安裝
(應用場景就是邀請別人免填邀請碼下載安裝等,邀請碼的信息在鏈接的自定義參數里,比如下載鏈接https://app-**********.openinstall.io/channel-landing?phoneNumber=13***********,被邀請的用戶安裝后,openinstall獲取自定義參數,然后可以在注冊的時候,通過接口將這個參數值上傳到后台服務器)
1.在openinstall官網,點擊Android集成,點擊APK包,點擊上傳APK文件

2.在這個界面下面的列表里,點擊測試

3.在彈出的框里的key寫入在application里寫的要獲取的自定義的參數名稱,點擊生成測試連接
4.點擊連接跳轉到下載apk的界面,點擊立即使用,下載apk,安裝到手機上

5.刪除以前的包,安裝下載的包到手機上,打開,看結果(channel沒設置,自定義參數獲取到了)

第十一步:在需要一鍵拉起的activity里添加代碼
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OpenInstall.getWakeUp(getIntent(), wakeUpAdapter);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 此處要調用,否則App在后台運行時,會無法截獲
OpenInstall.getWakeUp(intent, wakeUpAdapter);
}
AppWakeUpAdapter wakeUpAdapter = new AppWakeUpAdapter() {
@Override
public void onWakeUp(AppData appData) {
//獲取渠道數據
String channelCode = appData.getChannel();
//獲取綁定數據
String bindData = appData.getData();
Log.d("appData", "getWakeUp : wakeupData = " + appData.toString());
}
};
@Override
protected void onDestroy() {
super.onDestroy();
wakeUpAdapter = null;
}
第十二步:在AndroidManifest.xml的喚醒頁面activity標簽中添加intent-filter(一般為MainActivity),配置scheme,用於瀏覽器中拉起
<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="******"/>
</intent-filter>
第十三步:上傳apk,設置自定義參數和值,生成鏈接和二維碼,掃下二維碼,手機跳轉到鏈接的界面,點擊立即使用,就自動跳轉到程序上

第十四步:查看一鍵拉起的獲取的參數的值

第十五步:配置渠道參數
點擊渠道管理,添加渠道,然后點擊渠道鏈接顯示https://app-*****.openinstall.io/channel-landing?channelCode=00000111(這里有渠道信息channelCode,但是這個鏈接沒有自定義參數,上面有自定義有參數的鏈接但是沒有渠道信息,如果我兩個都想要,(這個連接都是后台生成,后台給的,我這里就拼接下)https://app-*********.openinstall.io/js-test/android/1047412755738029502?duanzishou=%E5%A4%A7%E5%BC%A0%E4%BC%9F&channelCode=00000111)

第十六步:將拼接的鏈接在草料二維碼網站(https://cli.im/url)生成二維碼

第十七步:掃二維碼,下載apk,安裝,打開,測試參數有沒有獲取到

第十八步:注冊量統計(看業務需求)
//用戶注冊成功后調用OpenInstall.reportRegister();
第十九步:看應用統計和渠道報表