2015-04-28 57 views
0

我一直在試圖通過WhatsApp的通過份額意圖送的位置,到目前爲止我的代碼:分享意圖位置

String uri = "geo:" + currentLoc.getLatitude() + "," +currentLoc.getLongitude() + "?q=" + currentLoc.getLatitude() + "," + currentLoc.getLongitude(); 
      Intent i=new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); 
      startActivity(i); 

的問題是,當應用程序選擇器打開它只顯示「谷歌地圖」和「位智」。我如何修改它,以便我可以通過許多其他支持像whatsapp或facebook這樣的位置的應用程序發送它?

回答

0

嘗試使用下面的代碼,這是官方文檔中的一個示例。

Intent sendIntent = new Intent(); 
sendIntent.setAction(Intent.ACTION_SEND); 
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my location to send."); 
sendIntent.setType("text/plain"); 
startActivity(sendIntent); 

public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.share, menu); 
    MenuItem item = menu.findItem(R.id.share_item); 
    actionProvider = (ShareActionProvider) item.getActionProvider(); 

    // Create the share Intent 
    String shareText = URL_TO_SHARE; 
    Intent shareIntent = ShareCompat.IntentBuilder.from(this) 
     .setType("text/plain").setText(shareText).getIntent(); 
    actionProvider.setShareIntent(shareIntent); 
    return true; 
} 

另一個選項,您可以直接指定應用程序通過向您的意圖添加包名打開您的意圖。

sendIntent.setPackage("com.whatsapp"); 
startActivity(sendIntent); 

請,更多信息檢查文檔whatsappandroid