我需要SharedPreferences在android中保存几个日期并检索它.我正在使用构建提醒应用程序AlarmManager,我需要保存未来日期列表.它必须能够以毫秒为单位进行检索.首先,我想要计算今天时间和未来时间之间的时间,并以共享偏好存储.但是这个方法不起作用,因为我需要使用它AlarmManager.
我正在尝试实施Joda-Time倒计时到圣诞节,但到目前为止,我很震惊.我尝试了java.util.Date和大多数建议使用Joda-Time的StackOverflow问题和答案.但我无法让它发挥作用.一些代码给出不同的答案.
这是我试过的一些代码,
DateTime now = new DateTime();
DateTime christmas = new DateTime(2012, 12, 25, 8, 0, 0, 0);
Days daysToChristmas = Days.daysBetween(today, christmas);
System.out.println(daysToChristmas.toString());
Run Code Online (Sandbox Code Playgroud)
这打印P187D作为答案.
DateTime start = new DateTime(DateTime.now());
DateTime end = new DateTime(2012, 12, 25, 0, 0, 0 ,0);
Interval interval = new Interval(start, end);
Period period = interval.toPeriod();
System.out.println("Seconds " + period.getSeconds());
System.out.println("Minutes " + period.getMinutes());
System.out.println("Hours " + period.getHours());
System.out.println("Days " + period.getDays());
Run Code Online (Sandbox Code Playgroud)
这打印出以下结果,
Seconds 36
Minutes 21
Hours 7
Days 4 …Run Code Online (Sandbox Code Playgroud) 我试图通过MediaRecorder录制音频,但出现错误,我试图更改所有内容,但无济于事。最近两个小时,我尝试查找错误,我也使用Log类,并且发现它在调用recorder.start()方法时发生了错误。可能是什么问题呢?
public class AudioRecorderActivity extends Activity {
MediaRecorder recorder;
File audioFile = null;
private static final String TAG = "AudioRecorderActivity";
private View startButton;
private View stopButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startButton = findViewById(R.id.start);
stopButton = findViewById(R.id.stop);
setContentView(R.layout.main);
}
public void startRecording(View view) throws IOException{
startButton.setEnabled(false);
stopButton.setEnabled(true);
File sampleDir = Environment.getExternalStorageDirectory();
try{
audioFile = File.createTempFile("sound", ".3gp", sampleDir);
}catch(IOException e){
Toast.makeText(getApplicationContext(), "SD Card Access Error", Toast.LENGTH_LONG).show();
Log.e(TAG, "Sdcard access error"); …Run Code Online (Sandbox Code Playgroud) 我遇到了以下sql语句,你可以看到AUTO_INCREMENT位于两个不同的地方.你能解释一下不同吗,我知道第一个是自动递增id.但第二个意味着什么呢?
CREATE TABLE `categories`(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`image_path` varchar(200) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB;
Run Code Online (Sandbox Code Playgroud)
第二个声明.
CREATE TABLE `categories`(
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`image_path` varchar(200) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT=4 ;
Run Code Online (Sandbox Code Playgroud)
我引用了http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html.但我找不到任何东西.
我成功测试了Blobstore上传教程.但它使用serve方法来查看文件.我找不到任何方法来获取文件路径.通常在php中我们上传文件时会得到文件路径,因此我们可以将该文件嵌入到html中.我怎么能在BlobStore中做到这一点.我搜索stackoverflow和谷歌,我可以找到python示例,但我找不到任何Java.