2017-11-13 9 views
0

私はAndroidスタジオにはかなり新しく、2つのマップアプリの中から選択する可能性がアプリに追加されました。しかし、私は悪名高い "Always open/just once"メソッドを追加する方法を知りたがっています。いつも一度だけメソッドを追加するには?

private void launchNextActivity(String latitude, String longitude, int state) { 
    for (int i = 0; i < User.getUserCourses().size(); i++) { 
     if (User.getUserCourses().get(i).getIdCourse() == course.getIdCourse()) { 
      //A remplacer par l'appel de l'api 
      Intent intent; 

      Location location = getLastKnownLocation(); 
      if (location == null) { 
       Toast.makeText(getApplicationContext(), "Connexion avec le serveur impossible", Toast.LENGTH_SHORT).show(); 
       return; 
      } 
      String uri = "google.navigation:q=" + latitude + "+" + longitude; 
      uri = uri.replace(" ", "+"); 
      intent = new Intent(Intent.ACTION_VIEW, 
        Uri.parse(uri)).setPackage("com.google.android.apps.maps"); 
      if (intent == null) { 
       findViewById(R.id.cancel_button).setClickable(false); 
       Snackbar 
         .make(findViewById(R.id.snackbar_position), "Google Map missing", Snackbar.LENGTH_LONG) 
         .setAction("Download", new View.OnClickListener() { 
          @Override 
          public void onClick(View view) { 
           try { 
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"))); 
           } catch (android.content.ActivityNotFoundException anfe) { 
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.maps"))); 
           } 
           findViewById(R.id.cancel_button).setClickable(true); 
          } 
         }) 
         .setActionTextColor(getResources().getColor(R.color.ShGreen2)) 
         .show(); 
      } 

      //Load Waze if available 
      Intent wazeIntent; 
      String uriWaze = "https://waze.com/ul?ll=" + latitude + "," + longitude + "&navigate=yes"; 
      wazeIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uriWaze)).setPackage("com.waze"); 

      Intent chooserIntent = Intent.createChooser(intent, "Ouvrir l'itinéraire avec:"); 
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { wazeIntent }); 
      reloadActivity(state, chooserIntent); 
     } 

これは実際にどのように実際に動作するかに関する情報をほとんど一切検索していません。私は常に私はそれを常に起動する選択肢を呼び出すので、しかし、どのように "いつも/ 1回だけ"を選択せず​​に開いて追加することを知っていますか?

答えて

1

geo URI schemeを使用して、ユーザーのデフォルトマップアプリケーション内の場所を開くことができます(デフォルトのアプリケーションが設定されていない場合は、「常に開く/一回だけ」ダイアログが表示されます)。

Uri location = Uri.parse("geo:" + latitude + "," + longitude); 
Intent intent = new Intent(Intent.ACTION_VIEW, location); 
if (intent.resolveActivity(getPackageManager()) != null) { 
    startActivity(intent); 
} 
+0

ありがとうございます!それはまさに私が必要なものでした!今は完璧に動作します。 ^^ – Max

関連する問題