クラウドからデータを取得はできるけどtimestampが1970年からの秒数になっているため改良しましょう6/6

This commit is contained in:
nemukemo 2024-06-06 18:46:27 +09:00
parent 4e65216874
commit 8c0f2530a5
2 changed files with 43 additions and 29 deletions

View File

@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "317219128586",
"project_id": "oplogy-b6971",
"storage_bucket": "oplogy-b6971.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:317219128586:android:c29583456e8fbd5f12a6f3",
"android_client_info": {
"package_name": "com.example.oplogy"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyDaULi2TFHLiscR7DSZBCKS08d76Rtb49c"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}

View File

@ -46,33 +46,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
time=findViewById(R.id.editTime);
//データの追加(適当なデータを追加しています実際にはデータベースに保存したいデータを追加してください)
findViewById(R.id.btnAdd).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
User user = new User(number.getText().toString(), address.getText().toString(),date.getText().toString(),time.getText().toString());
db.collection("users")
.add(user)
.addOnSuccessListener(documentReference -> Log.d("@FB1", "DocumentSnapshot added with ID: " + documentReference.getId()))
.addOnFailureListener(e -> Log.w("@FB1", "Error adding document", e));
}
});
btnShow.setOnClickListener(v -> {
// Read Data
// Firestoreのコレクションusersのドキュメント一覧を取得する
// 非同期で取得処理が動作する結果を受け取るために処理完了時のリスナーをセットする
db.collection("users").get().addOnCompleteListener(task -> {
db.collection("questionnaireForms").get().addOnCompleteListener(task -> {
String data = "";
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d("@FB1", document.getId() + "=>" + document.getData());
User user = document.toObject(User.class);
data += user + "\n";
data += document.getId() + "=>" + document.getData() + "\n";
}
} else {
data = "Error getting documents." + task.getException().getMessage();
@ -81,6 +63,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
});
btnShow.setOnClickListener(v -> {
});