type
status
date
slug
summary
tags
category
icon
password
参数应用集成
导入sdk依赖
implementation 'com.whatspos.sdk:paxstore-3rd-app-android-sdk:8.4.0'
加上权限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
具体操作
首先需要在开发者中心创建一个应用
获取应用的key和密钥
在代码中集成sdk,并且初始化
在根application中初始化连接,这里就需要key和密钥
public class MyApp extends Application { private static final String TAG = MyApp.class.getSimpleName(); //todo 确保key和secret的正确 private String appkey = "KB96YTJ*****6QAN6BL2"; private String appSecret = "P87H92OT1RDOL**************T0PDRZME7P6ZT"; private static Context appContext; @Override public void onCreate() { super.onCreate(); appContext = getApplicationContext(); dal = getDal(); //初始化paxstore链接 initPaxStoreSdk(); } //建立与maxstore的连接 private void initPaxStoreSdk() { //todo Init AppKey,AppSecret, make sure the appKey and appSecret is corret. StoreSdk.getInstance().init(getApplicationContext(), appkey, appSecret, new BaseApiService.Callback() { @Override public void initSuccess() { //TODO Do your business here Log.d(TAG, "initSuccess: MAXSTORE 商店链接成功"); } @Override public void initFailed(RemoteException e) { //TODO Do failed logic here Toast.makeText(getApplicationContext(), "不能连接MAXSTORE商店,请先安装MAXSTORE.", Toast.LENGTH_LONG).show(); } }); } }
接收推送的参数文件,由于推送的参数文件是由maxstore唤起所以有两种一种是广播唤起,还有一种是aidl直接唤起service。这里使用的是service,首先需要创建一个service来写下载的逻辑。
public class DownloadParamService extends IntentService { private final String TAG ="商店下载参数文件"; public String saveFilePath; public DownloadParamService() { super("DownloadParamService"); } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } @Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { NotificationUtils.showForeGround(this, "Downloading params"); return super.onStartCommand(intent, flags, startId); } //可以在此写下载的逻辑 @Override protected void onHandleIntent(@Nullable Intent intent) { //指定下载的地址 saveFilePath = getFilesDir() + "/WWW/"; System.out.println(saveFilePath); DownloadResultObject downloadResult = null; try { //下载,并保存下载结果,三个参数分别是应用完整包名,应用版本,保存路径 downloadResult = StoreSdk.getInstance().paramApi().downloadParamToPath(getApplication().getPackageName() , com.pax.laitengyu.myapplication.BuildConfig.VERSION_CODE,, saveFilePath); } catch (NotInitException e) { Log.e(TAG, "e:" + e); } //businesscode==0, 就是下载成功, 如果不是0就检查错误消息 if(downloadResult != null && downloadResult.getBusinessCode()==0){ Log.i("downloadParamToPath: ", "参数文件下载成功"); File displayFile = getDisplayFile(); Log.d("文件路径名字为", displayFile.getPath()); //file download to saveFilePath above. //todo 这里可以添加一些成功逻辑 }else{ //todo 检查错误信息 Log.e("downloadParamToPath: ", "ErrorCode: "+downloadResult.getBusinessCode()+"ErrorMessage: "+downloadResult.getMessage()); } } //查找获取下载文件 private File getDisplayFile() { File parameterFile = null; File[] filelist = new File(saveFilePath).listFiles(); if (filelist != null && filelist.length > 0) { for (File f : filelist) { //todo Noted. this is for demo only, here hard code the xml name to "sys_cap.p". this demo will only parse with the specified file name if ("test_param".equals(f.getName())) { parameterFile = f; } String name = f.getName(); Log.d("文件名字", name); } } return parameterFile; } }
别忘记注册,这里注册比较特殊,需要指定这个?(不太清楚)
<service android:name=".DownloadParamService"> <intent-filter> <action android:name="com.sdk.service.ACTION_TO_DOWNLOAD_PARAMS"/> <category android:name="${applicationId}"/> </intent-filter> </service>
到这里,一个可以接收参数的应用就写完了,如何接收呢?
接收ActivityDemo
通过parseDownloadParamXml()方法解析成hashmap,还有解析json的方法(未写)详情可以看这。
public class ParamActivity extends AppCompatActivity implements View.OnClickListener { private static final String TAG = "参数接收"; private TextView ptext1,ptext2; private Button paramBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_param); ptext1=findViewById(R.id.param_text1); ptext2=findViewById(R.id.param_text2); paramBtn=findViewById(R.id.param_btn); paramBtn.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.param_btn: //注意解析文件操作不能在主线程中进行 new Thread(()->{ //明确文件地址 File file = new File(getFilesDir() + "/WWW/test_param"); boolean exists = file.exists(); Log.d(TAG, " "+exists); //用hashMap存储解析的xml键值对 HashMap<String, String> stringStringHashMap; try { //使用parseDownloadParamXml讲xml文件解析为hashmap stringStringHashMap = StoreSdk.getInstance().paramApi().parseDownloadParamXml(file); Set<Map.Entry<String, String>> entries = stringStringHashMap.entrySet(); Iterator<Map.Entry<String, String>> iterator = entries.iterator(); while(iterator.hasNext()){ Map.Entry<String, String> next = iterator.next(); Log.d(TAG,next.getKey()+" "+next.getValue()); } String ltyzqhh = stringStringHashMap.get("test.buttontext1"); Log.d(TAG, " "+ltyzqhh+" 实例化成功"); runOnUiThread(()->{ //将取出的值放入textview ptext1.setText(ltyzqhh); ptext2.setText(stringStringHashMap.get("text.button2")); }); } catch (ParseXMLException e) { e.printStackTrace(); } catch (NotInitException e) { e.printStackTrace(); } }).start(); break; // case R.id.print_pic: // // break; default: break; } } }
推送参数应用的参数(验证)
首先
需要将这个app上架,并设置为参数应用设置参数模板。测试机子需要安装maxstore,并注册。
参数模板
在开发者中心→平台服务→自定义参数模板创建(注意此为创建xml,与最后解析的文件无关,最后推送的文件将由maxstore解析后生成另一个xml文件,也不必过多关心),可导入以下例子参考,需要注意Files里面的
<FileName>
就是文件最后的名字,这里没写.xml后缀,所以生成的文件也不带后缀,这是失误,需要改正,还是规范加上后缀,方便自己拿取的参数文件。<PID>
是参数的键, <Defaultvalue>
是参数的值,通过api可以转换存在hashmap里。<?xml version="1.0" encoding="UTF-8"?> <Schema> <Groups> <Group> <ID>test_G1</ID> <Title>test1</Title> </Group> </Groups> <Files> <File> <ID>test_F1</ID> <FileName>test_param</FileName> <FileType>xml</FileType> </File> </Files> <Parameters> <Header> <Title>test</Title> <DisplayStyle>foldable</DisplayStyle> <DefaultStyle>open</DefaultStyle> <Display>true</Display> <Parameter> <Type>single</Type> <InputType>text</InputType> <PID>test.buttontext1</PID> <Title>参数1</Title> <Defaultvalue>推送的按钮</Defaultvalue> <Display>true</Display> <GroupID>test_G1</GroupID> <FileID>test_F1</FileID> </Parameter> <Parameter> <Type>single</Type> <InputType>text</InputType> <PID>text.button2</PID> <Title>参数2</Title> <Defaultvalue>另一个推送的参数</Defaultvalue> <Display>true</Display> <GroupID>test_G1</GroupID> <FileID>test_F1</FileID> </Parameter> </Header> </Parameters> </Schema>
准备好参数后就需要推参数了
进入管理员界面通过应用的申请的app,找到需要测试的机子选择应用和应用参数,激活推送。接着就看有没有接收成功了

在此修改参数

激活并推送

- 作者:内河
- 链接:https://ltyzqhh.top/article/%E5%AD%A6%E4%B9%A0maxstore
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章