我目前有两个版本的应用,付费版和免费版。 但我想在安装捐赠包时删除捐赠偏好.. 有什么想法吗?
此代码已检查已安装捐赠应用
public boolean isDonate() {
try
{
PackageInfo info = context.getPackageManager().getPackageInfo("com.example.test.donate",
PackageManager.GET_META_DATA);
Log.d(TAG, "Pro app is installed: " + info.applicationInfo.name);
return context.getPackageManager().checkSignatures("com.example.test",
"com.example.test.donate") == PackageManager.SIGNATURE_MATCH;
}
catch (NameNotFoundException e)
{
return false;
}
}
想要删除此偏好
xml代码:
<com.example.test.IconPreferenceScreen
android:key="goto_pro"
android:title="@string/go_to_pro"
android:summary="@string/go_to_pro_summary" />
java代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
IconPreferenceScreen pro = (IconPreferenceScreen) findPreference("goto_pro");
Resources res = getResources();
Drawable icon = res.getDrawable(R.drawable.playstore);
pro.setIcon(icon);
getPreferenceManager()
.findPreference("goto_pro")
.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.test"));
startActivity(intent);
return true;
}
});
答案 0 :(得分:1)
将它放在您的偏好活动的onCreate:
中Preference mPref = getPreferenceScreen().findPreference("goto_pro");
getPreferenceScreen().removePreference(mPref);