How to Accept Parameter Files Downloaded from TMS: Difference between revisions

From wizarPOS
No edit summary
Line 1: Line 1:
== How to configure parameter file in WizarView ==
== How to Configure a Parameter File in WizarView ==
Please refer to the WizarView specification.
=== <big>Add a New Parameter File in WizarView:</big> ===
=== <big>Configure any format parameter file</big> ===
* Navigate to ''''Applications > Application'''' in WizarView.
# Add a new parameter file name in WizarView.
* Click the + icon at the bottom left of the toolbox to open an edit window.[[File:Customizeparam.png|none|300px|left|caption]]
## Click Applications > Application.
* In the edit window, enter the name and other required details. Select 'param' as the type.
## Click + icon in the left bottom of the tool box, popup an edit window.[[File:Customizeparam.png|none|300px|left|caption]]
* Enter the package name of the app set to receive the parameter file (usually defined in ''''AndroidManifest.xml'''').
## In the edit window, input the name and other input area, then select type param.
* Input the parameter file name and click the ''''Commit'''' button.
## Input the package name of the app which will receive the parameter file. Generally, it defines in AndroidManifest.xml, package attribute in manifest element.
=== <big>Search and Upload the Parameter File:</big> ===
## Input parameter file name.
* On the ''''Applications > Application page'''', select 'param' type and click the ''''Search'''' button.
## Click Commit button.
* Choose the parameter file from the list.
# In the Applications>Application page, choose param type, then click Search button.
* Click the configuration icon, then select the ''''Upload'''' button in the popup window.
# Select the parameter file name in the list.
* Choose the file to upload and click ''''Commit''''.
# Select config icon in the right bottom of the tool box.
=== <big>Configure a Parameter File with a Template:</big> ===
# Select Upload button in the popup window.
# Choose the upload file, then click Commit button.
The parameter file is configured in WizarView now.
The process of push file is the same with push application.
 
=== <big>Configure parameter file with template</big> ===
[[File:Templates.png|none|100px|left|caption]]
[[File:Templates.png|none|100px|left|caption]]
* Select Templates > Configuration File, then click (+) icon in the left bottom of the tool box, in the popup window, choose group, input the name and other input area, choose the configuration file, click Commit button.
* Go to ''''Templates > Configuration File''''. Click the + icon and choose group, input the name and other input area, including selecting the configuration file,then click Commit button.
[[File:Configurefile.png|none|400px|left|caption]]
[[File:Configurefile.png|none|400px|left|caption]]
Here is a example of the configuration file, [http://ftp.wizarpos.com/advanceSDK/CrediCardFile_MIR_TestParam.xml testparam], in configuration file, all type should be string, the others should change depends on your real requirement.
Here is a example of the configuration file, [http://ftp.wizarpos.com/advanceSDK/CrediCardFile_MIR_TestParam.xml testparam], in configuration file, all type should be string, the others should change depends on your real requirement.
* Select Templates > Template, then click (+) icon in the left bottom of the tool box, in the popup window, input the name and other input area, select the configuration file created in the first step, input the package name of the app which will accept the template parameter.
* For ''''Templates > Template'''', Click the + icon, input the name and other input area, select the configuration file created in the first step, create a new template and specify the app's package name that will accept the template parameter.
[[File:Templatecreate.png|none|400px|left|caption]]
[[File:Templatecreate.png|none|400px|left|caption]]
* Select Terminals>Terminal, select the serial number of the POS you want to push template parameter.
* Under ''''Terminals > Terminal'''', select the serial number of the POS to push the template parameter to.  
* Select Config Application parameter icon in the bottom toolbox, in the popup window, click Add button in the left bottom, select the template parameter created and modify the value in the UI, then you can push it like push an app.
* Select Config Application parameter icon in the bottom toolbox, in the popup window, click Add button in the left bottom, select the template parameter created and modify the value in the UI and push it like an app.
[[File:Addapppram.png|none|700px|left|caption]]
[[File:Addapppram.png|none|700px|left|caption]]
 
== How to Receive Parameter Files in the Application ==
== How to receive parameter files in applicaion ==
* '''First-Time Run Requirement:''' Upon the first installation of the application, ensure to run it at least once. This is necessary to register the broadcast receiver, which is crucial for receiving parameter files.
Follow the instructions below to write the application to receive the parameter file. If the application is installed for the first time, you need to run it to register the broadcast receiver. After that, even if it is not running in the background, it will be triggered when you push the parameter file and press "Settings - > About POS - > POS Configuration - > Update now" on the terminal.
* '''Update Trigger:''' After the initial run, the app doesn’t need to be actively running in the background. The trigger for receiving new parameters is activated by pushing the parameter file and then navigating on the terminal to: ''''Settings > About POS > POS Configuration > Update now''''.
=== Permission ===
=== <big>Declare Permissions:</big> ===
* In your application's manifest file, declare the following permissions:
   android.permission.CLOUDPOS_PUSHSERVICE
   android.permission.CLOUDPOS_PUSHSERVICE
   android.permission.CLOUDPOS_DOWNLOADRVICE
   android.permission.CLOUDPOS_DOWNLOADRVICE
The application declares the permissions in manifest.
=== <big>Register BroadcastReceiver:</big> ===
 
* Utilize an Android ''''BroadcastReceiver'''' to receive notifications about pushed parameter files.
=== Register BroadcastReceiver ===
* Note: Pay attention to the 'type' field in the pushed information, as it helps distinguish different types of third-party data being pushed to your application.
Use android BroadcastReceiver to get pushing notice. Here is the demo:
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Line 71: Line 65:
}
}
</syntaxhighlight >
</syntaxhighlight >
Please notice that the pushed information has a type field, it is used to distinguish the third-party information pushed.
=== <big>Retrieve the Downloaded File:</big> ===
 
* Use the ''''BroadcastReceiver'''' to obtain the name of the received parameter file.
=== Get downloaded file name ===
* Then, employ ''''ContentResolver'''' to access the file stream and handle the file accordingly.
Use BroadcastReceiver to get parameter file's name. And use ContentResolver to get file stream. Here is the demo:
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
String URI_PARAM_FILE = "content://com.wizarpos.wizarviewagent.paramfilesprovider/file/";
String URI_PARAM_FILE = "content://com.wizarpos.wizarviewagent.paramfilesprovider/file/";
Line 87: Line 80:
}  
}  
</syntaxhighlight >
</syntaxhighlight >
=== The callback of the result of distribute parameters ===
=== <big>Handling Distribution Results:</big> ===
Send the distributed result to WizarView, WizarView will decide weather the parameter file is completed.
* After processing the parameter file, communicate the results back to WizarView.
If completed, stop the push. Otherwise, it will push all the time.Here is the demo:
* WizarView will then determine whether the parameter file distribution is complete. If it’s not marked as complete, WizarView may continue to push the file.
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
public static final String KEY_READED = "readed";
public static final String KEY_READED = "readed";
Line 111: Line 104:


</syntaxhighlight >
</syntaxhighlight >
 
== Demo Application: ==
===Sample===
For a practical demonstration and further understanding, please download our [http://ftp.wizarpos.com/advanceSDK/ParamFileReceiverDemo.tar.gz complete project demo]. This sample will provide a clearer idea of the implementation.
Please download the [http://ftp.wizarpos.com/advanceSDK/ParamFileReceiverDemo.tar.gz whole project demo]

Revision as of 22:27, 11 January 2024

How to Configure a Parameter File in WizarView

Add a New Parameter File in WizarView:

  • Navigate to 'Applications > Application' in WizarView.
  • Click the + icon at the bottom left of the toolbox to open an edit window.
    caption
  • In the edit window, enter the name and other required details. Select 'param' as the type.
  • Enter the package name of the app set to receive the parameter file (usually defined in 'AndroidManifest.xml').
  • Input the parameter file name and click the 'Commit' button.

Search and Upload the Parameter File:

  • On the 'Applications > Application page', select 'param' type and click the 'Search' button.
  • Choose the parameter file from the list.
  • Click the configuration icon, then select the 'Upload' button in the popup window.
  • Choose the file to upload and click 'Commit'.

Configure a Parameter File with a Template:

caption
  • Go to 'Templates > Configuration File'. Click the + icon and choose group, input the name and other input area, including selecting the configuration file,then click Commit button.
caption

Here is a example of the configuration file, testparam, in configuration file, all type should be string, the others should change depends on your real requirement.

  • For 'Templates > Template', Click the + icon, input the name and other input area, select the configuration file created in the first step, create a new template and specify the app's package name that will accept the template parameter.
caption
  • Under 'Terminals > Terminal', select the serial number of the POS to push the template parameter to.
  • Select Config Application parameter icon in the bottom toolbox, in the popup window, click Add button in the left bottom, select the template parameter created and modify the value in the UI and push it like an app.
caption

How to Receive Parameter Files in the Application

  • First-Time Run Requirement: Upon the first installation of the application, ensure to run it at least once. This is necessary to register the broadcast receiver, which is crucial for receiving parameter files.
  • Update Trigger: After the initial run, the app doesn’t need to be actively running in the background. The trigger for receiving new parameters is activated by pushing the parameter file and then navigating on the terminal to: 'Settings > About POS > POS Configuration > Update now'.

Declare Permissions:

  • In your application's manifest file, declare the following permissions:
 android.permission.CLOUDPOS_PUSHSERVICE
 android.permission.CLOUDPOS_DOWNLOADRVICE

Register BroadcastReceiver:

  • Utilize an Android 'BroadcastReceiver' to receive notifications about pushed parameter files.
  • Note: Pay attention to the 'type' field in the pushed information, as it helps distinguish different types of third-party data being pushed to your application.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your package name, which will configure in TMS package name area."

<!-- permission in manifest file-->
<uses-permission android:name="android.permission.CLOUDPOS_PUSHSERVICE" />
<uses-permission android:name="android.permission.CLOUDPOS_DOWNLOADRVICE" />

<!-- receiver in manifest file-->
<receiver
android:name="com.xxx.xxx.receiver.XXBroadcastReceiver">
    <intent-filter>
    	<action android:name="your package name" />
</intent-filter>
</receiver>

<!-- receiver snippet code-->
public class ParamFileReceiver extends BroadcastReceiver {
		
		private static final String MSG_TYPE_PARAM = "param:";
		@Override
		public void onReceive(Context context, Intent intent) {
			String notification = intent.getStringExtra("notification");
			if (notification != null
	&&MSG_TYPE_PARAM.equals(notification.subSequence(0,
MSG_TYPE_PARAM.length()))) {
				// remove unnecessary characters
				String fileName = notification
                                      .substring(MSG_TYPE_PARAM.length());
			}
		}
	}
}

Retrieve the Downloaded File:

  • Use the 'BroadcastReceiver' to obtain the name of the received parameter file.
  • Then, employ 'ContentResolver' to access the file stream and handle the file accordingly.
String URI_PARAM_FILE = "content://com.wizarpos.wizarviewagent.paramfilesprovider/file/";

Uri uri = Uri.parse(ParamFileProvider.URI_PARAM_FILE + fileName);
ContentResolver resolver = context.getContentResolver();
Reader reader = null;
try {
	reader = new InputStreamReader(resolver.openInputStream(uri));
} catch (FileNotFoundException e) {
e.printStackTrace();
}

Handling Distribution Results:

  • After processing the parameter file, communicate the results back to WizarView.
  • WizarView will then determine whether the parameter file distribution is complete. If it’s not marked as complete, WizarView may continue to push the file.
public static final String KEY_READED = "readed";
public static final String KEY_ERRLOG = "errlog";

String URI_PARAM_FILE = "content://com.wizarpos.wizarviewagent.paramfilesprovider/file/";

Uri uri = Uri.parse(ParamFileProvider.URI_PARAM_FILE + fileName);
ContentResolver resolver = context.getContentResolver();
ContentValues vaules = new ContentValues();

vaules.put("readed", true);
vaules.put("readed", false);
vaules.put("errlog", "Error in parameter information.Can not apply");

// give the result to the server
Uri resultUri = resolver.insert(uri, vaules);
if(resultUri == null){
	Log.e(APP_TAG, "param happen error , you need check log for modify this question!");
}

Demo Application:

For a practical demonstration and further understanding, please download our complete project demo. This sample will provide a clearer idea of the implementation.