20170127 使用Intent啟動程式的方式(快速撥號)

//20170127 劉彥廷
//使用Intent啟動程式的方式(快速撥號)

MainActivity.java

package com.example.user.myapplication45;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;


public class MainActivity extends AppCompatActivity {




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public void onClick(View v){


        Intent it = new Intent(); //
        it.setAction(Intent.ACTION_VIEW);
        it.setData(Uri.parse("tel:098058025"));

        startActivity(it);
    }


    public void callbaby(View v){


        Intent it = new Intent(); //
        it.setAction(Intent.ACTION_VIEW);
        it.setData(Uri.parse("tel:123456789"));

        startActivity(it);
    }
}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.user.myapplication45.MainActivity">

    <Button
        android:text="@string/callbaby"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2"
        android:layout_weight="1"
        android:onClick="callbaby" />

    <Button
        android:text="@string/call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        android:layout_weight="1"
        android:onClick="onClick" />
</LinearLayout>

string.xml

<resources>
    <string name="app_name">快速撥號No45</string>
    <string name="call">打給老爸</string>
    <string name="callbaby">打給寶貝</string>
</resources>



留言

這個網誌中的熱門文章

IOS_Objective-C學習筆記_(陣列 / 可修改陣列 ;字典 / 可修改字典)..

20170122 Radiobutton功能練習 (溫度轉換)

iOS_開發 拿到 Tableview Cell 上的按鈕是哪一個 (Tableview Cell Button)