I want to change datetime in my android app using joda Datetime using my below code. steps:
- get current date of system
- set system hours
- get current date and check the result.
There was no error pop-up while running this app. But the time was not change.
Is there anything that im missing? Do I need to get more permission in Manifest.xml?
Note that the app will be run on a rooted emulator.
My file as below:
MainActivity.java;
private void settime1(){
List<String> text = new ArrayList<>();
DateTime now = DateTime.now();
Toast.makeText(MainActivity.this,now.toString(), Toast.LENGTH_LONG).show();
text.add("Now: " + now);
text.add("Now + 12 hours: " + now.plusHours(12));
Date currentTime = Calendar.getInstance().getTime();
Toast.makeText(MainActivity.this, currentTime.toString(), Toast.LENGTH_LONG).show();
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.us_bbteam">
buid.gradle
dependencies {
api 'joda-time:joda-time:2.10.9:no-tzdb'
implementation "androidx.startup:startup-runtime:1.0.0"
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'com.google.android.things:androidthings:1.0'
implementation 'net.danlew:android.joda:2.10.9.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}