2012-04-11 45 views
0

我正在開發具有共享偏好,包含一個Android應用程序: - 鈴聲(完成)SharedPreference在安卓(告訴朋友+禁用對話框通知)

  • 關閉對話框通知(報警,SMS,MMS )(尚未,請閱讀代碼中的註釋)

- 告訴朋友(我相信我的代碼是正確的,但我不知道如何把它帶共用偏好+我現在是肯定的地方,方法,我應該把它 - 請閱讀代碼內的評論)

public class Setting extends PreferenceActivity{ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    addPreferencesFromResource(R.xml.prefs); 
} 
@Override 
protected void onStart() { 
    // TODO Auto-generated method stub 
    super.onStart(); 
    String ringtonePreference; 
    // Get the xml/preferences.xml preferences 
        SharedPreferences prefs = PreferenceManager 
            .getDefaultSharedPreferences(getBaseContext()); 
    ringtonePreference = prefs.getString("ringtonePref", 
            "DEFAULT_RINGTONE_URI"); 

} 
    //disable all Notification (Alarm , SMS,MMS) 
    //what is the method that i should put this code at it? onStart?onDestroy?or what? 
SharedPreferences sharedPreferences = this.getPreferences(MODE_PRIVATE); 
boolean hideNotification = sharedPreferences.getBoolean("checkbox", false); 

if(!hideNotification) 
    alertDialog.show(); 
} 

//tell friend 
//i am not sure if this is right place to this code 
    //if it is the right place then what is the method that i should put this code at it?onStart?onActivityResult?or what? 

SharedPreferences prefs1 = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 
TellFriendPreference = prefs1.getString("tellfriend","null"); 
@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    String item = (String) getListAdapter().getItem(position); 
    String str= item.toString(); 
    if(str=="Tell Friends"){ 
     Toast.makeText(this,"First", Toast.LENGTH_LONG).show(); 
     //Go to tell friend activity 
     //Intent i = new Intent (Help.this, .class); 
     //startActivity(i); 
     Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
     intent.setType("text/plain"); 
     intent.putExtra(android.content.Intent.EXTRA_TEXT, "Check out s Application for Android. Download it today from http://s.com"); 
     startActivity(Intent.createChooser(intent, "Tell friends:")); 

     startActivity(intent); 




} 

這是的prefs.xml

<?xml version="1.0" encoding="utf-8"?> 
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > 

    <PreferenceCategory android:title="Second Category" > 
    <RingtonePreference 
     android:name="Ringtone Preference" 
     android:key="ringtonePref" 
     android:summary="Select a ringtone" 
     android:title="Ringtones" /> 

    <CheckBoxPreference 
     android:defaultValue="true" 
     android:key="checkbox" 
     android:summary="Check the Box" 
     android:title="Disable Notification" /> 
    <Preference 
     android:name="tell Preference" 
     android:key="tellfriend" 
     android:summary="if u want to tell ur friends by usinf" 
     android:title="Tell Friend" /> 
    </PreferenceCategory> 

    </PreferenceScreen> 

請幫助我,我要幾個小時

+0

幫助請! – Maha 2012-04-12 09:14:09

回答

0

我解決我的問題後提交。我只是在另一個活動中告訴朋友,我的代碼是正確的。