I am using the following code to open the calendar app:
class Appointments : AppCompatActivity() {
lateinit var tv:TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_appointments)
tv = findViewById(R.id.textView4)
tv.setOnClickListener(View.OnClickListener {
var callIntent = Intent(Intent.ACTION_EDIT)
.setType("vnd.android.cursor.item/event")
startActivityForResult(callIntent, 3);
})
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == 3 && resultCode == Activity.RESULT_OK && data!=null){
Toast.makeText(this@Appointments,"Some data came",Toast.LENGTH_SHORT).show()
} else{
Toast.makeText(this@Appointments,"Some Error",Toast.LENGTH_SHORT).show()
}
}
}
I keep getting 'some error' message. I tried removing 'data!=null' but I think the resultcode is the problem.
What I 'finally' want to achieve is this:
- User opens the app
- User clicks on a button to open the calendar app
- User is able to see the calendar and then the user makes an appointment in the calendar
- User comes back to the app and I am able to extract the date and time of the new appointment
Is it possible to do? If yes then some code example will be much appreciated. If it is not possible then what are the other ways to achieve this?