【问题标题】:How to fix the error "unsafe implementation of PreferenceActivity classes"?如何修复错误“PreferenceActivity 类的不安全实现”?
【发布时间】:2017-08-24 02:44:58
【问题描述】:

我收到错误消息“您的应用正在使用不安全的 PreferenceActivity 类实现,这使得它们容易受到片段注入的影响。”来自 Google Play。

我已阅读https://support.google.com/faqs/answer/7188427?hl=enYour implementation of PreferenceActivity is vulnerable to fragment injection

这是否意味着 PreferenceActivity 类已过时?我该如何解决这个问题?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.dodata.unlock"
    android:versionCode="8"
    android:versionName="1.08" >

    <uses-sdk  android:minSdkVersion="9"  android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />    
    <uses-permission android:name="com.android.vending.BILLING" />     

    <application
        android:allowBackup="true"
        android:icon="@drawable/unlockwithwifi"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >   


       <activity
            android:name="ui.UnlockMain"
            android:launchMode="singleTop" 
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>    


        <activity android:name="ui.UnlockAddWiFi"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="ui.UnlockAddWiFi" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>             


        <activity android:name="ui.LockPreference">
            <intent-filter>
                <action android:name="ui.LockPreference" />
                <category android:name="android.intent.category.PREFERENCE" />
            </intent-filter>
        </activity>      

        ... 

    </application>

</manifest>

LockPreference.java

public class LockPreference  extends PreferenceActivity{

     private AdView adView;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);         
            addPreferencesFromResource(R.xml.unlockpreference);
            setContentView(R.layout.unlock_custom_preference);

            adView=(AdView) findViewById(R.id.adView);
            PublicParFun.SetAD(adView);         

            SetDisplayIcon();

            Button btnClose=(Button)findViewById(R.id.btnClosePreference);
            btnClose.setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    finish();
                }           
            });         
     } 
     ...    

}

unlockpreference.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="AppPreference"
    android:summary="@string/PreferenceSummary"
    android:title="@string/Preference" >

    <ui.custom.DialogChangePassword
       android:key="ChangePassword"
       android:dialogIcon="@android:drawable/ic_dialog_alert"
       android:title="@string/ChangePasswordTitle"
       android:summary="@string/ChangePasswordSummary"      
       android:positiveButtonText="@string/BtnSave"
       android:negativeButtonText="@string/BtnCancel"
       android:layout="@layout/unlock_custom_preference_item"  
    />      

    <CheckBoxPreference
       android:defaultValue="true"
       android:key="DisplayNotificationIcon"
       android:title="@string/DisplayNotificationIconTitle"
       android:summary="@string/DisplayNotificationIconSummary"  
       android:layout="@layout/unlock_custom_preference_item" 
    />    

</PreferenceScreen>

【问题讨论】:

    标签: android


    【解决方案1】:

    添加首选项的首选方法是在正常活动中使用首选项片段。使用框架布局创建一个正常的活动并创建将使用首选项屏幕显示首选项的首选项片段。 看到这个https://developer.android.com/guide/topics/ui/settings.html#Fragment

    【讨论】:

    • github.com/codepath/android_guides/wiki/… 查看它已实现的此 wiki 页面
    • 谢谢!类 PreferenceActivity 过时了吗?
    • 不,它还没有过时,但从您的警告消息来看,Google 可能会放弃对此的支持。
    • 还有,如果最小 API 是 9,我该如何修复错误。 BTW API 9 不支持 PreferenceFragment
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2012-02-07
    相关资源
    最近更新 更多