2017-08-24 4 views
0

「あなたのアプリはPreferenceActivityクラスの安全でない実装を使用しているため、フラグメント注入の影響を受けやすい」というエラーが表示されます。 Google Playから「PreferenceActivityクラスの安全でない実装」というエラーを修正するにはどうすればよいですか?

私はそれがクラスPreferenceActivityが時代遅れであることを意味していhttps://support.google.com/faqs/answer/7188427?hl=en

Your implementation of PreferenceActivity is vulnerable to fragment injectionを読んだことがありますか?どのように問題を解決できますか?

enter image description here

の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> 

答えて

0

好みを追加するための好ましい方法は、通常のアクティビティで嗜好フラグメントを使用することです。フレームレイアウトで通常のアクティビティを作成し、プリファレンス画面を使用してプリファレンスを表示するプリファレンスフラグメントを作成します。 これを参照してくださいhttps://developer.android.com/guide/topics/ui/settings.html#Fragment

+0

ありがとう!完全なサンプルコードを教えてください。 – HelloCW

+0

https://github.com/codepath/android_guides/wiki/Settings-with-PreferenceFragmentこのwikiページを見る実装済み –

+0

ありがとう! PreferenceActivityクラスは廃止されましたか? – HelloCW

関連する問題