android中的共享首选项(告诉朋友+禁用对话通知)

时间:2012-04-11 23:17:59

标签: java android

我正在开发一个具有共享首选项的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>

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

1 个答案:

答案 0 :(得分:0)

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