zoukankan      html  css  js  c++  java
  • Android学习笔记(十七)——使用意图调用内置应用程序

    使用意图调用内置应用程序


    1、创建一个新的Android项目并命名为Intents,在main.xml文件里加入两个Button:

        <Button
            android:id="@+id/btn_webbrowser"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:onClick="onClickWebBrowser"
            android:text="Web Browser" />
    
        <Button
            android:id="@+id/btn_makecalls"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:onClick="onClickMakeCalls"
            android:text="Make Calls" />
    
    

    2、在IntentsActivity.java文件里加入例如以下代码:

    	public void onClickWebBrowser(View v) {//浏览器
    		Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
    				Uri.parse("http://网址"));//网址处输入百度网址,CSDN不让直接写网址...
    		startActivity(intent);
    	}
    
    	public void onClickMakeCalls(View v) {//打电话
    		Intent intent = new Intent(android.content.Intent.ACTION_DIAL,
    				Uri.parse("tel:+651234567"));
    		startActivity(intent);
    	}
    
    

    3、执行程序,效果例如以下:


    点击Web Browser:


    点击Make Calls:



    总结:

    在Android中,意图一般是成对出项:动作(Action)和数据(data)。动作描写叙述了要运行什么,数据则指定了受影响的对象。

    动作的一些演示样例:Action_VIEW、ACTION_DIAL、ACTION_PICK;

    数据的一些演示样例:tel:+651234567、geo:37.827500,-122.481670、content://contacts。

  • 相关阅读:
    C语言之回调函数&模块化
    680. 验证回文字符串 Ⅱ
    C++指针数组和数组指针
    345. 反转字符串中的元音字母
    633.平方数之和
    IDM使用介绍篇
    路由器无线桥接WDS
    约数的个数
    密码翻译
    查找学生信息
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4256299.html
Copyright © 2011-2022 走看看