admin管理员组文章数量:1345700
I cannot open a folder to windows explorer using a native module (C++ UWP).
I tried following the appropriate manner UWP C++
StorageFolder folder{ co_await StorageFolder::GetFolderFromPathAsync(filePath) };
OutputDebugStringW(L"openFolder StorageFolder passed.\n");
bool launched = co_await Launcher::LaunchFolderAsync(folder); // <-Error happened
...
catch (const winrt::hresult_error& ex)
{
std::wstringstream ss;
ss << L"[openFolder] Error: " << ex.message().c_str() << L"\n";
OutputDebugStringW(ss.str().c_str());
promise.Resolve(false);
co_return;
}
I get an error when I click on the button in the interface of the React-Native Windows app (the app is active and in focused). I run the app using "npx react-native start --reset-cache" and "npx react-native run-windows".
I get the fabulous error (DebugView) :
Error: A method was called at an unexpected time.
I tried normalising the path before doing the StorageFolder does not change the outcome.
I also tried "ShellExecuteW" but no luck on this side. I would prefer to use the approved method for UWP.
My manifest has "<rescap:Capability Name="broadFileSystemAccess"/>" and I tried adding "<rescap:Capability Name="runFullTrust" />" same result. The app is authorised in the Privacy settings for filesystem and I read and write files outside approved UWP folders without any issues.
I tried to open different locations and I always get that error.
Any help would be much appreciated.
Edit: I tried to integrate it as a button in the UI and click manually on the button to trigger the call like that :
const CustomModule: {
openFolder(filePath: string): Promise<boolean>;
} = NativeModules.NativeReactModule;
Then in memo :
<View key={key}><Button title="Open" onPress={() => onRowButtonPressOpenFolder(item)} /></View>
Finally :
const onRowButtonPressOpenFolder = useCallback(async () => {const openFolder: any = await CustomModule.openFolder(route.params.folder);}, []);
本文标签:
版权声明:本文标题:React Native Windows: C++ UWP - How to open a folder : LaunchFolderAsync-> (A method was called at an unexpected time) - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743773419a2536536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论