我正在为 Xpose 创建一个模块,它可以实现我想要的功能,但我想为用户提供一个简单的首选项屏幕来输入两个整数值。
我主要用的教程可以找到here on XDA .
教程解释说,必须创建一个 Activity 来显示和管理首选项屏幕,好吧。但在那之后,根本没有解释如何将其链接到 Xpose,以便用户可以单击模块列表中的模块名称并访问首选项屏幕,相反,我只是收到一条消息“该模块不提供用户界面” ”。
我没有找到任何有关如何执行此操作的文档。有人可以告诉我这个吗?
最佳答案
我想我已经找到了罪魁祸首(至少这为我解决了问题)。看来Xposed automatically detects if the app has launchable activity ,然后就开始了。没有 API。来源:Xpose源码:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String packageName = (String) v.getTag();
if (packageName == null)
return;
if (packageName.equals(NOT_ACTIVE_NOTE_TAG)) {
Intent intent = new Intent(getActivity(), XposedInstallerActivity.class);
intent.putExtra(XposedInstallerActivity.EXTRA_SECTION, XposedDropdownNavActivity.TAB_INSTALL);
startActivity(intent);
return;
}
Intent launchIntent = getSettingsIntent(packageName);
if (launchIntent != null)
startActivity(launchIntent);
else
Toast.makeText(getActivity(), getActivity().getString(R.string.module_no_ui), Toast.LENGTH_LONG).show();
}
因此,您只需要创建一个 Activity ,但我认为这还不够:您还必须在 Eclipse 中将其设为“启动器 Activity ”,或者您可以通过添加 CATEGORY_LAUNCHER
来手动完成此操作> Intent 过滤器。
如果它有效,当您将应用程序从 eclipse 推送到测试手机时,该应用程序将自动打开(就像任何其他应用程序一样)。如果发生这种情况,通常该应用程序也应该在 Xposed 中打开。
例如,这是我放入 my class 中的内容:
package xxx.xxx.xxx;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
public class MainSettingsActivity extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Setup a non-default and world readable shared preferences, so that 1- we know the name (necessary for XSharedPreferences()), 2- the preferences are accessible from inside the hook.
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName("pref_mine");
prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.pref_settings);
}
}
然后在主类中使用钩子(Hook)内的首选项:
public class Main implements IXposedHookLoadPackage {
public XSharedPreferences pref;
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
XSharedPreferences pref = new XSharedPreferences(Main.class.getPackage().getName(), "pref_mine"); // load the preferences using Xposed (necessary to be accessible from inside the hook, SharedPreferences() won't work)
pref.makeWorldReadable();
pref.reload();
pref.getString("some_var", "default_value");
...
关于android - Xpose 如何创建带有 GUI 首选项屏幕的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32555529/