Intent 的使用功能、打開網頁、發送mail、打電話、拍照、打開地圖、打開圖片、打開網頁的儲存空間
package ccc.test;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.Button;
public class IntentTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonUrl = (Button) findViewById(R.id.ButtonUrl);
Button buttonEmail = (Button) findViewById(R.id.ButtonEmail);
Button buttonTel = (Button) findViewById(R.id.ButtonTel);
Button buttonCamera = (Button) findViewById(R.id.ButtonCamera);
Button buttonGMap = (Button) findViewById(R.id.ButtonGMap);
Button buttonImage = (Button) findViewById(R.id.ButtonImage);
Button buttonPeople = (Button) findViewById(R.id.ButtonPeople);
Button buttonMarket = (Button) findViewById(R.id.ButtonMarket);
buttonUrl.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁
Uri uri=Uri.parse("http://www.google.com.tw");
Intent i=new Intent(Intent.ACTION_VIEW,uri);
startActivity(i);
}
});
buttonEmail.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //發送mail
Uri uri=Uri.parse("mailto:ccc@nqu.edu.tw");
Intent i=new Intent(Intent.ACTION_SENDTO,uri);
startActivity(i);
}
});
buttonTel.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打電話
Uri uri=Uri.parse("tel:082313532");
Intent i=new Intent(Intent.ACTION_VIEW,uri);
startActivity(i);
}
});
buttonCamera.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //拍照
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(i);
}
});
buttonGMap.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開地圖
Uri uri = Uri.parse("geo:25.048,121.532");
Intent i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
}
});
buttonImage.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開圖片
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(i, 0);
}
});
buttonPeople.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁
Intent i = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);
startActivity(i);
}
});
buttonMarket.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁的儲存空間
Uri uri = Uri.parse("market://search?q=dropbox");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
}
});
}
}
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.Button;
public class IntentTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonUrl = (Button) findViewById(R.id.ButtonUrl);
Button buttonEmail = (Button) findViewById(R.id.ButtonEmail);
Button buttonTel = (Button) findViewById(R.id.ButtonTel);
Button buttonCamera = (Button) findViewById(R.id.ButtonCamera);
Button buttonGMap = (Button) findViewById(R.id.ButtonGMap);
Button buttonImage = (Button) findViewById(R.id.ButtonImage);
Button buttonPeople = (Button) findViewById(R.id.ButtonPeople);
Button buttonMarket = (Button) findViewById(R.id.ButtonMarket);
buttonUrl.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁
Uri uri=Uri.parse("http://www.google.com.tw");
Intent i=new Intent(Intent.ACTION_VIEW,uri);
startActivity(i);
}
});
buttonEmail.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //發送mail
Uri uri=Uri.parse("mailto:ccc@nqu.edu.tw");
Intent i=new Intent(Intent.ACTION_SENDTO,uri);
startActivity(i);
}
});
buttonTel.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打電話
Uri uri=Uri.parse("tel:082313532");
Intent i=new Intent(Intent.ACTION_VIEW,uri);
startActivity(i);
}
});
buttonCamera.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //拍照
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(i);
}
});
buttonGMap.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開地圖
Uri uri = Uri.parse("geo:25.048,121.532");
Intent i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
}
});
buttonImage.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開圖片
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(i, 0);
}
});
buttonPeople.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁
Intent i = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);
startActivity(i);
}
});
buttonMarket.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) { //打開網頁的儲存空間
Uri uri = Uri.parse("market://search?q=dropbox");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
}
});
}
}
留言
張貼留言