Open Waze GPS navigation or google map with Intent

Viewed 3156

I try to open the navigation with a click of a button, in the choice of gps applications, I waze and google maps. When I click on google map, the navigation starts correctly but when I click on waze navigation does not start. I just get my position

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,

Uri.parse("google.navigation:q=22+dizengoff+street+netanya"));
            startActivity(intent);

Ir all my code:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); //Que le clavier soit par defaut ferme

    init();
}

public void init(){
    //Reglage des bouton par ID
    btnAdd = findViewById(R.id.maAddUser);
    btnMap = findViewById(R.id.maBtnMap);


    //On click sur les boutons
    btnAdd.setOnClickListener(this);
    btnMap.setOnClickListener(this);
}


@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.maAddUser:
            //Redirection vers l'activity ADDUSER
            Intent goAddUser = new Intent(MainActivity.this, AddUserActivity.class);
            startActivity(goAddUser); //Redirection vers ADD USER
            break;
        case R.id.maBtnMap:
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                    Uri.parse("google.navigation:q=22+dizengoff+street+netanya"));
            startActivity(intent);
            break;
    }
}
3 Answers
try {
    // Launch Waze
    String mapRequest = "https://waze.com/ul?q=" + latLng.latitude + "," + latLng.longitude + "&navigate=yes&zoom=17";
    Uri gmmIntentUri = Uri.parse(mapRequest);
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.waze");
    startActivity(mapIntent);

    } catch (ActivityNotFoundException e) {
    // If Waze is not installed, open it in Google Play
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.waze"));
    startActivity(intent);
    }
Related