I am trying to make a clone of Uber Driver app. I got this part covered, where upon receiving a client's request notification, the app will prompt an App Chooser for user choose what 3rd party app (e.g. Google Map or Waze) to navigate to the client's location after the user chose to accept client's request.
public static final int APP_CHOOSER_LOCATION = 101;
acceptBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String uri = "geo:" + locationInfo.getLatitude() + ","
+locationInfo.getLongitude() + "?q=" + locationInfo.getLatitude()
+ "," + locationInfo.getLongitude();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivityForResult(intent, APP_CHOOSER_LOCATION);
isBack = true;
}
});
So the problem is how do I know user has finish with his/her navigation?
My current solution is putting an indicator isBack
. By default it will be false
. When user has click accept, isBack
is set to true
.
So, in the onResume function, if isBack
is equal to true
, it will proceed to open another activity.
@Override
public void onResume(){
super.onResume();
if(isBack){
// Proceed to open another actvity
isBack = false;
}
}
However, this does not work if the user click the Cancel button.
App Chooser Screenshot
I tried using onActivityResult
but the resultCode
always shows 0 (or RESULT_CANCELED
) no matter what app I clicked.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "in onActivityResult ");
Log.i(TAG, "resultCode:: "+resultCode);
if (requestCode == APP_CHOOSER_RESPONSE){
if(resultCode == RESULT_OK){
Log.i(TAG, "user select app ");
if(isBack){
// Proceed to open another activity
isBack = false;
}
}
if(resultCode == RESULT_CANCELED){
Log.i(TAG, "is cancelled by user ");
isBack = false;
}
}
}
Is my approach wrong? Or did I miss anything in my code? I am stuck here and I do not know how to proceed. Any advice is appreciated.