0

我正在开发一个具有共享偏好的 android 应用程序,其中包含: - 铃声(完成)

  • 禁用对话框通知(闹钟、短信、彩信)(还没有,请阅读代码内的注释)

- 告诉朋友(我确定我的代码是正确的,但我不确定如何使用共享偏好设置 + 我现在确定应该使用的位置和方法 - 请阅读代码中的注释)

 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>

请帮助我,我应该在几个小时后提交

4

1 回答 1

0

我解决了我的问题。我只是在另一个活动中告诉朋友,我的代码是正确的。

于 2012-04-28T15:46:29.940 回答