在回话界面的ACTIVITY实现RongIM.ConversationBehaviorListener,重写onMessageClick 方法,代码如下:
@Override public boolean onMessageClick(Context context, View view, Message arg2) { if (arg2.getContent() instanceof LocationMessage) { Intent intent = new Intent(ConversationActivity.this, GuideActivity.class); intent.putExtra("location", arg2.getContent()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return true; } else { return false; } }注:GuideActivity为自定义的点击位置消息后弹出的界面,此类代码如下:
public class GuideActivity extends RongBaseActivity { private MapView mAMapView; private LinearLayout guide; private double lat; private double lng; private String poi; public GuideActivity() { } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(io.rong.imkit.R.layout.rc_location_preview_activity); this.mAMapView = (MapView) this.findViewById(io.rong.imkit.R.id.rc_ext_amap); this.mAMapView.onCreate(savedInstanceState); TextView title = (TextView) this.findViewById(io.rong.imkit.R.id.rc_action_bar_title); title.setText(io.rong.imkit.R.string.rc_plugin_location); this.initMap();
guide = (LinearLayout) findViewById(R.id.guide);//这是增加的按钮,点击调用百度地图,实现导航功能 new Thread(new Runnable() { @Override public void run() { guide.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:" + lat + "," + lng + "|name:我的位置&destination="+poi+"&mode=driving®ion=&referer=Autohome|GasStation#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end"); if (isInstallByread("com.baidu.BaiduMap")) { startActivity(intent); //启动调用 Log.e("GasStation", "百度地图客户端已经安装"); } else { Log.e("GasStation", "没有安装百度地图客户端"); Toast.makeText(GuideActivity.this, "请先安装百度地图", Toast.LENGTH_SHORT).show(); } } catch (URISyntaxException e) { e.printStackTrace(); } } }); } }).start(); } private void initMap() { AMap amap = this.mAMapView.getMap(); amap.setMyLocationEnabled(true); amap.getUiSettings().setZoomControlsEnabled(false); amap.getUiSettings().setMyLocationButtonEnabled(false); Intent intent = this.getIntent(); LocationMessage locationMessage = (LocationMessage) intent.getParcelableExtra("location"); lat = locationMessage.getLat(); lng = locationMessage.getLng(); poi = locationMessage.getPoi(); amap.addMarker((new MarkerOptions()).anchor(0.5F, 0.5F).position(new LatLng(lat, lng)).title(poi).snippet(lat + "," + lng).draggable(false)); amap.moveCamera(CameraUpdateFactory.newCameraPosition((new CameraPosition.Builder()).target(new LatLng(lat, lng)).zoom(16.0F).bearing(0.0F).tilt(30.0F).build())); } private boolean isInstallByread(String packageName) { return new File("/data/data/" + packageName).exists(); } protected void onDestroy() { this.mAMapView.onDestroy(); super.onDestroy(); }