Exit from google maps intent in android -


i implementing custom turn-by-turn navigation in android application. achieve this, have started activity mainactivity using intent uses intent.action_view action , "google.navigation:q" uri string.the google maps navigation page loaded in app.

but, don't know how gracefully exit page. if use button press, takes 4 button clicks display main activity screen. there possibility place "exit" button in page.

i have tried "onactivityforresult" , "onbackpressed" destroying google maps screens. none of works. please provide suggestions go further.

i know pretty late answer maybe can someone.

you cannot come google map activity/app on single press need create floating view/widget ola/uber after proper implementation. here implementation.

first user go map app youractivity. in activity ask permission system_alert_window (draw over, sdk > marshmallow) on click of view. launch google map service created create floating icon.

class youractivity extends appcompatactivity{  private getfloatingiconclick mgetserviceclick; public static boolean isfloatingiconservicealive = false;  oncreate(){     mgetserviceclick = new getfloatingiconclick();      somebtn.onclick(){         askdrawoverpermission();     } }  private class getfloatingiconclick extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         intent selfintent = new intent(youractivity.this, youractivity.class);         selfintent.setflags(intent.flag_activity_reorder_to_front | intent.flag_activity_single_top                 | intent.flag_activity_clear_top);         startactivity(selfintent);     } }  private void askdrawoverpermission() {     if (build.version.sdk_int < build.version_codes.m) {         // if os pre-marshmallow create floating icon, no permission needed         createfloatingbackbutton();     } else {         if (!settings.candrawoverlays(this)) {             // asking draw_over permission in settings             intent intent = new intent(settings.action_manage_overlay_permission,                     uri.parse("package:" + getapplicationcontext().getpackagename()));             startactivityforresult(intent, req_code_draw_over);         } else {             createfloatingbackbutton();         }     } }  // starting service creating floating icon on map private void createfloatingbackbutton() {     intent iconserviceintent = new intent(youractivity.this, floatingovermapiconservice.class);     iconserviceintent.putextra("ride_id", str_rideid);      intent navigation = new intent(intent.action_view, uri             .parse("google.navigation:q=" + lat_dest + "," + lng_dest + "&mode=d"));     navigation.setpackage("com.google.android.apps.maps");     startactivityforresult(navigation, 1234);      startservice(iconserviceintent); }  @targetapi(build.version_codes.m) @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == req_code_draw_over) {         // permissions settings don't provide callbacks, hence checking again permission         // can draw our floating without asking user click on clicked view         // again         if (settings.candrawoverlays(this)) {             createfloatingbackbutton();         } else {             //permission not provided user, task             //globalvariables.alert(mcontext, "this permission necessary application's functioning");         }     } else if (requestcode == 1234) {         // no result returned google map, google don't provide apis or documentation         // it.     } else {         super.onactivityresult(requestcode, resultcode, data);     } } } 

service class:-

public class floatingovermapiconservice extends service { private windowmanager windowmanager; private framelayout framelayout; private string str_ride_id; public static final string broadcast_action = "com.yourpackage.youractivity";  @nullable @override public ibinder onbind(intent intent) {     return null; }  @override public void oncreate() {     super.oncreate();     createfloatingbackbutton(); }  @override public int onstartcommand(intent intent, int flags, int startid) {     // receive data activity     str_ride_id = intent.getstringextra("ride_id");     return start_sticky; }  @override public void ondestroy() {     super.ondestroy();     windowmanager.removeview(framelayout); }  private void createfloatingbackbutton() {      currentjobdetail.isfloatingiconservicealive = true;      windowmanager.layoutparams params = new windowmanager.layoutparams(             windowmanager.layoutparams.wrap_content,             windowmanager.layoutparams.wrap_content,             windowmanager.layoutparams.type_phone,             windowmanager.layoutparams.flag_not_focusable,             pixelformat.translucent);     params.gravity = gravity.left | gravity.center_vertical;      windowmanager = (windowmanager) getsystemservice(window_service);     framelayout = new framelayout(this);      layoutinflater layoutinflater = (layoutinflater) getsystemservice(layout_inflater_service);      // here place can inject whatever layout want in frame layout     layoutinflater.inflate(r.layout.custom_start_ride_back_button_over_map, framelayout);      imageview backonmap = (imageview) framelayout.findviewbyid(r.id.custom_drawover_back_button);     backonmap.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent intent = new intent(broadcast_action);             intent.putextra("ride_id", str_ride_id);             sendbroadcast(intent);              //stopping service             floatingovermapiconservice.this.stopself();             currentjobdetail.isfloatingiconservicealive = false;         }     });      windowmanager.addview(framelayout, params); } } 

floating icon xml:-

<linearlayout  android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">  <imageview     android:id="@+id/custom_drawover_back_button"     android:layout_width="70dp"     android:layout_height="100dp"     android:src="@drawable/common_full_open_on_phone"     android:scaletype="center"     android:background="@color/coloraccent"/> </linearlayout> 

manifest file :-

<uses-permission android:name="android.permission.system_alert_window" />  <activity         android:name=".activities.youractivity"         android:launchmode="singletop" />  <service         android:name=".utils.floatingovermapiconservice"         android:exported="false" /> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -