i am trying to connect two android devices using WIFI direct and i was successful. But the problem is the second device has to accept the a connection prompt after the other
This can be achieve using Xposed framework. You need add the code and install the App. The phone needs to be rooted in order for it to work. I have tested it on multiple Samsung phones and it works. Check this answer for details: How to auto-accept Wi-Fi Direct connection requests in Android
You could indeed simply use the createGroup function from the API to create a group, which also makes the access point. The first problem here is that the access point name & password are set automatically, and you can not change them.
So, you do need to pass the info to the connecting party, and for this, I would suggest using the local service advertising, and using the instance name there.
Did make simple test app for this and you can find it from Github under DrJukka/MyWifiMesh, also some discussions on the topic can be found from my blog