我知道这个话题已被讨论很多但不是这个含义.我需要将日志存储在.txt文件中,但我不能使用log4j或任何其他类,但android.util.log我有这个解决方案,但它不是最好的.具有与以下相同的信息:Log.i(TAG,"一个信息消息"); 我要写...
ERROR = logLevel < 3;
WARNING = logLevel < 2;
INFO = logLevel < 1;
if (INFO){
appendLog("LEVEL: I TIME: "+java.util.GregorianCalendar.DAY_OF_MONTH +
"-"+ java.util.GregorianCalendar.MONTH +" "+GregorianCalendar.HOUR_OF_DAY +":"+GregorianCalendar.MINUTE +
":"+GregorianCalendar.SECOND +"."+GregorianCalendar.MILLISECOND + " PID: "+
android.os.Process.myPid()+ " TID: "+android.os.Process.myTid()+ " Application: com.example.myapplication"+
" TAG:" +TAG+ " TEXT: An INFO Message");
}
Run Code Online (Sandbox Code Playgroud)
然后...
public void appendLog(String text) {
File logFile = new File("sdcard/log.txt");
if (!logFile.exists()) {
try {
logFile.createNewFile();
}catch (IOException e){
e.printStackTrace();
}
}
try {
BufferedWriter buf = …
Run Code Online (Sandbox Code Playgroud) 该程序第一次创建首选项,但之后它永远不会更改它们.我很感激帮助理解为什么.
这是调用xml的PreferencesScreen.
public class PreferencesScreen extends PreferenceFragment{
private final String TAG = "PreferencesScreen";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "OnCreate");
addPreferencesFromResource(R.xml.prefs);
}
Run Code Online (Sandbox Code Playgroud)
在首选项中,我有一个ListPreference和一个Preference,它调用一个活动来存储电子邮件.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Information Collected">
<ListPreference
android:key="loggins"
android:title="Logs Stored"
android:summary="Choose the top kind of logs do you want to store."
android:dialogTitle="Choose Logs"
android:entries="@array/logs"
android:entryValues="@array/logsValues"/>
</PreferenceCategory>
<PreferenceCategory android:title="Email Configurations">
<Preference
android:key="pushing"
android:title="The Email Activity"
android:summary="Just push">
<intent android:action = "ADDING_EMAIL"/>
</Preference>
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
一切都在这里.问题出在所谓的......
public class AddingEmail extends ListActivity implements OnClickListener{
private Set<String> emails;
private …
Run Code Online (Sandbox Code Playgroud)