How to access app details and write app version number into a file?

33 ビュー (過去 30 日間)
Martti Ilvesmäki
Martti Ilvesmäki 2021 年 6 月 28 日
コメント済み: Francisco Sacchetti 2024 年 11 月 12 日 15:57
I'm trying out functionalities of Appdesigner in order to see it can handle specifications of app I'm designing.
I want my app to include possibility for writing an info file which contains version number of the app. I noticed this is located in Appdesigner in "App details".
My question is, how to access this information in order to write it into a file using a button in the app?
  2 件のコメント
Mili Goyal
Mili Goyal 2021 年 6 月 28 日
I think this MATLAB answer is very similar to what you have asked.
Do check this out!
Martti Ilvesmäki
Martti Ilvesmäki 2021 年 6 月 29 日
Thank you, I checked it out. The answer of the question is a MATLAB technical support team provided function which, if I understood correctly, works for shared apps with app installer.
I would like to however, access this information from the app itself if possible. For example, by clicking button "write info file" which would write a .txt or .csv file containing information about the app and the version number.

サインインしてコメントする。

採用された回答

Kishan Dhakan
Kishan Dhakan 2021 年 6 月 30 日
You can use the property app.<your app name>UIFigure.Name to acess the app name and write it to csv or txt using MATLAB functions in the button callback. For example, in your component browser, look for the first component under your app name, it should be the UIFigure. Use app.<thatComponent>.Name to access app name (and similar for other details like version).
  2 件のコメント
Martti Ilvesmäki
Martti Ilvesmäki 2021 年 7 月 5 日
Thank you, this works as a workaround. For example by using app.UIFigure.Tag for version number. Still though couldn't directly access App Details version number.

サインインしてコメントする。

その他の回答 (1 件)

Brian
Brian 2021 年 11 月 16 日
I developed the below yesterday and it has seemed to work so far.
function ver = CheckVersion(~)
if isdeployed % If compiled and deployed
[~, result] = system('path');
p = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once')); % Get run path
myDir=dir(fullfile(p,'..','appdata','components')); % Move to components folder and get all files
myDir=myDir(3:end); % Exclude '.' and '..'
validFile=myDir(datetime({myDir.date})==max(datetime({myDir.date}))); % Only look at most recent install, includes 'common' and 'platform'
appInfo=xml2struct(fullfile(validFile(1).folder,validFile(1).name)); % Import 'common' as struct from xml (requires xml2struct download)
ver=appInfo.componentData.component.componentVersion.Text; % Grab the version number as a char array
else
fullpath=mfilename('fullpath'); % Get run path
s=settings;
if ~isempty(strfind(fullpath,s.matlab.addons.InstallationFolder.ActiveValue)) % If the run path includes the addons install folder, it is run from the app bar
[p,~]=fileparts(fullpath); % Get the path
if isfolder(fullfile(p,'resources'))
xmlLocation=fullfile(p,'resources','addons_core.xml'); % Go to resources folder
appInfo=xml2struct(xmlLocation); % Import addons_core.xml as struct
ver=appInfo.addonCore.version.Text; % Grab the version number as a char array
else
ver='debug'; % This may be redundant with below. Left in to prevent errors just in case...
end
else % If run from MATLAB mlapp file
ver='debug';
end
end
end
  3 件のコメント
Han Geerligs
Han Geerligs 2024 年 5 月 22 日
Does anyone know how to retrieve the version of an .mlapp file?
This property is available on top level of the GUI, in picture below it is 1.02. I'd like to display it in a text label.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by