Files
YukiHookAPI/docs/assets/xposed-storage.html.cd1e83bb.js

13 lines
7.9 KiB
JavaScript

import{_ as e,o as s,c as o,a}from"./app.fb8271cf.js";const n={},t=a(`<h1 id="xposed-module-data-storage" tabindex="-1"><a class="header-anchor" href="#xposed-module-data-storage" aria-hidden="true">#</a> Xposed Module Data Storage</h1><blockquote><p>This is an efficient Module App data storage solution that automatically connects <code>SharedPreferences</code> and <code>XSharedPreferences</code>.</p></blockquote><p>We need to store the data of the Module App for the Host App to call.</p><p>At this time, we will encounter the data exchange obstacle of the native <code>Sp</code> storage.</p><p>The native <code>Xposed</code> provides us with a <code>XSharedPreferences</code> for reading the <code>Sp</code> data of the Module App.</p><h2 id="use-in-activity" tabindex="-1"><a class="header-anchor" href="#use-in-activity" aria-hidden="true">#</a> Use in Activity</h2><blockquote><p>Loading <code>YukiHookModulePrefs</code> in <code>Activity</code> is described here.</p></blockquote><p>Usually we can initialize it in Host App like this.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F69D50;">XSharedPreferences</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">BuildConfig</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">APPLICATION_ID</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Is there a convenient and quick solution?</p><p>At this point, you can use the extension capability of <code>YukiHookAPI</code> to quickly implement this function.</p><p>When you store data in a Module App, you can use the following methods if you are currently in an <code>Activity</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">modulePrefs.putString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>When you read data in a Host App, you can use the following methods.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.getString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>You don&#39;t need to consider the module package name and a series of complicated permission configurations, everything is handled by <code>YukiHookModulePrefs</code>.</p><p>To achieve localization of storage, you can specify the name of each <code>prefs</code> file.</p><p>This is used in the <code>Activity</code> of the Module App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Recommended usage</span></span>
<span class="line"><span style="color:#ADBAC7;">modulePrefs(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).putString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Can also be used like this</span></span>
<span class="line"><span style="color:#ADBAC7;">modulePrefs.name(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).putString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Read like this in Host App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Recommended usage</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).getString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Can also be used like this</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.name(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).getString(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If your project has a lot of fixed data that needs to be stored and read, it is recommended to use <code>PrefsData</code> to create templates.</p><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookModulePrefs">YukiHookModulePrefs</a>, <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData">PrefsData</a>.</p></div><h2 id="use-in-preferencefragment" tabindex="-1"><a class="header-anchor" href="#use-in-preferencefragment" aria-hidden="true">#</a> Use in PreferenceFragment</h2><blockquote><p>Loading <code>YukiHookModulePrefs</code> in <code>PreferenceFragment</code> is described here.</p></blockquote><p>If your Module App uses <code>PreferenceFragmentCompat</code>, you can now start migrating its extends <code>ModulePreferenceFragment</code>.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>You must extends <strong>ModulePreferenceFragment</strong> to implement the module storage function of <strong>YukiHookModulePrefs</strong>.</p></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/ui/ModulePreferenceFragment">ModulePreferenceFragment</a>.</p></div>`,33),l=[t];function p(i,c){return s(),o("div",null,l)}const d=e(n,[["render",p],["__file","xposed-storage.html.vue"]]);export{d as default};