我的应用程序中有经纬度,想要使用谷歌地图或Chrome浏览器等其他应用程序显示该位置。使用谷歌地图我可以通过创建像
这样的意图来实现String geoUriString = getResources().getString(R.string.map_location);
Uri geoUri = Uri.parse(geoUriString);
Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);
或者,如果我通过chrome浏览器进行操作,那么可以通过创建像
这样的意图来实现String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", sourceLatitude, sourceLongitude, destinationLatitude, destinationLongitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
但我只需要在Google地图和Chrome浏览器之间创建动作选择器。用户将根据自己的应用选择应用。我怎样才能做到这一点?
答案 0 :(得分:0)
您可以创建自己的自定义按钮,供用户在两个选项之间进行选择
将此添加到您的布局文件
<ScrollView
android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:fadeScrollbars="true"
android:fadingEdge="none"
android:isScrollContainer="true"
android:scrollbars="horizontal|vertical" >
<LinearLayout
style="@android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:orientation="vertical" >
<Button
android:id="@+id/chrome"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:drawableLeft="@drawable/chrome_icon"
android:drawablePadding="1px"
android:focusable="true"
android:gravity="bottom|left|center_vertical|top"
android:text="Chrome Browser"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold|italic" />
<Button
android:id="@+id/maps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:background="@color/transparent"
android:drawableLeft="@drawable/maps_icon"
android:drawablePadding="1px"
android:focusable="true"
android:gravity="bottom|left|center_vertical|top"
android:text="Google Maps"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold|italic" />
</LinearLayout>
</ScrollView>
//* then add the click listeners to your code.
//* Chrome
Button stopButton = (Button) findViewById(R.id.chrome);
stopButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
View scrollView = findViewById(R.id.HorizontalScrollView01);
scrollView.setVisibility(View.INVISIBLE);
//* add your code to start chrome
}
});
//* maps
Button playButton = (Button) findViewById(R.id.maps);
playButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
View scrollView = findViewById(R.id.HorizontalScrollView01);
scrollView.setVisibility(View.INVISIBLE);
//* add your code to start maps
}
});