利用Intent跳转其他程序的拓展

我们知道Intent跳转功能十分强大,可以通过设置属性可以从当前程序跳转到系统程序及其他程序,下面以几个常用的跳转为例做一个简单的实现。

布局文件如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.briup.intentexample.MainActivity" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="浏览器搜索“天气”"
        android:onClick="google" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="地图"
        android:onClick="map" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="路径规划"
        android:onClick="round" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="发短信"
        android:onClick="send" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="发送短信"
        android:onClick="sendto" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="录音机"
        android:onClick="sendc" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="详细信息"
        android:onClick="detail" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="联系人"
        android:onClick="open" />
	<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="联系人"
        android:onClick="open2" />
	
</LinearLayout>

Activity类文件如下

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Audio.Media;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
	public void google(View v){//使用浏览器,不限Google
		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_WEB_SEARCH);
		intent.putExtra(SearchManager.QUERY, "天气");
		startActivity(intent);
	}
	public void map(View v){//打开地图软件并定位指定坐标
		Uri uri = Uri.parse("geo:38.88995533,-77.0366576");
		Intent intent = new Intent(Intent.ACTION_VIEW,uri);
		startActivity(intent);
	}
	public void round(View v){//路径规划
		Uri uri = Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
		Intent intent = new Intent(Intent.ACTION_VIEW,uri);
		startActivity(intent);
	}
	public void send(View v){//发送短息
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.putExtra("sms_body", "SMS");//信息内容
		intent.setType("vnd.android-dir/mms-sms");
		startActivity(intent);
	}
	public void sendto(View v){//直接发送短信
		Uri uri = Uri.parse("smsto:18862000000");
		Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
		intent.putExtra("sms_body", "SMS");
		startActivity(intent);
	}
	public void sendc(View v){//打开录音机
		Intent intent = new Intent(Media.RECORD_SOUND_ACTION);
		startActivity(intent);
	}
	public void detail(View v){//显示应用详细信息
		Uri uri = Uri.parse("market://details?id=com.briup.intentexample");
		Intent intent = new Intent(Intent.ACTION_VIEW,uri);
		startActivity(intent);
	}
	public void open(View v){//SIM卡联系人
		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_GET_CONTENT);
		intent.setType("vnd.android.cursor.item/phone");
		startActivityForResult(intent, RESULT_CANCELED);
	}
	public void open2(View v){//本地联系人
		Uri uri = Uri.parse("content://contacts/people");
		Intent intent = new Intent(Intent.ACTION_PICK,uri);
		startActivityForResult(intent, RESULT_CANCELED);
	}
}

效果如下,不做具体测试


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值