본문 바로가기

나 어제 배웠다/Android

Android Implicit Intent 내장기능 호출

Android Implicit (암시) 처리

- 바로전화걸기 : Call

- 전화기능 호출 : Dial

- 기타기능 호출 : 오디오App

 

1. 프로젝트 생성

 

 

2. main.xml widget 추가

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 <Button
    android:id="@+id/b01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="action : ACTION_CALL"/>
   
 <Button
    android:id="@+id/b02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="action : ACTION_DIAL"/>
   
 <Button
    android:id="@+id/b03"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="action : ACTION_GET_CONTENT"/>
</LinearLayout>

 

 

3. NotificationTestActivity.java

package hjh.intent.implicit;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.*;

 

public class ImplicitiTestActivity extends Activity implements View.OnTouchListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        this.setInit();
        //자기 자신 호출
        b1.setOnTouchListener(this);
        b2.setOnTouchListener(this);
        b3.setOnTouchListener(this);

    }
   
    Button b1,b2,b3;
    void setInit(){
     b1 = (Button)findViewById(R.id.b01);
     b2 = (Button)findViewById(R.id.b02);
     b3 = (Button)findViewById(R.id.b03);
    }
   
    @Override
    public boolean onTouch(View v, MotionEvent event){
     if(v == b1){
      Intent i = new Intent(Intent.ACTION_CALL);
      i.setData(Uri.parse("tel:0123456789"));
      startActivity(i);
     }else if(v == b2){
      /*Intent i = new Intent(Intent.ACTION_DIAL);
      i.setData(Uri.parse("tel:0123456789"));*/
      Intent i = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:0123456789"));
      startActivity(i);
     }else{
      Intent i = new Intent(Intent.ACTION_GET_CONTENT);
      i.setType("audio/*");
      startActivity(i);
     }
     return false;
    }
}

 

 

4. AndroidManifest.xml 변경

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="hjh.intent.implicit"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ImplicitiTestActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />

 <!-- 전화걸기권한추가 -->
 <uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>

 

 

5. 실행결과