總網頁瀏覽量

關於我自己

我的相片
人生的必修課是接受無常,人生的選修課是放下執著。

2012年3月6日 星期二

以Uri為主的應用


ID 功能 code
1 開啟網頁, 需要網址 Uri uri= Uri.parse("http://google.com.tw");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
2 開啟地圖, 需要經緯度座標 Uri mapUri = Uri.parse("geo:25.183505,121.528873");
Intent intent = new Intent(Intent.ACTION_VIEW, mapUri);
startActivity(intent);
3 開啟電話AP, 並填入電話號碼 Uri telUri = Uri.parse("tel:0228825252");
Intent intent = new Intent(Intent.ACTION_DIAL, telUri);
startActivity(intent);
4 播打電話, 需要電話號碼 //得先在 AndroidManifest.xml 中加上<uses-permission id="android.permission.CALL_PHONE" />
Uri callUri = Uri.parse("tel:0228825252");
Intent intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
5 uninstall AP, 需要package名稱 Uri uninstallUri = Uri.fromParts("package", "com.tsots.contacts", null);
Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri);
startActivity(intent);
6 install AP, 需要package名稱 Uri installUri = Uri.fromParts("package", "com.tsots.contacts", null);
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
startActivity(intent);
7 播放多媒體, 需要檔案絕對路徑 Uri uri = Uri.parse("file:///sdcard/media/music.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, playUri);
intent.setDataAndType(uri, "audio/mp3");
startActivity(intent);
8 發郵件, 需要mail address //Uri emailUri = Uri.parse("mailto:beddingfair@gmail.com");
//Intent intent = new Intent(Intent.ACTION_SENDTO, emailUri);
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "beddingfair@gmail.com" };
String[] ccs = { "other@gmail.com" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Content");
intent.setType("message/rfc882");
startActivity(Intent.createChooser(it, "Choose Email Client"));
9 開啟簡訊AP, 並填入電話號碼&內文 Uri smsUri = Uri.parse("tel:0988123456");
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", "HelloDear");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
10 傳送簡訊, 需要電話號碼&內文 Uri uri = Uri.parse("mmsto:<number>");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("address", "0988123456");
intent.putExtra("subject", "HelloDear");
startActivity(intent);
11 傳送影音附件檔, 需要檔案位置&內文 Uri uri = Uri.parse("file:///sdcard/media/music.mp3");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
12 傳送圖片附件檔, 需要檔案位置&內文 Uri uri = Uri.parse("file:///sdcard/dcim/pic.jpg");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/jpeg");
startActivity(Intent.createChooser(it, "Choose Email Client"));
13 啟動照相機,拍照後將相片存在指定檔案 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//將相片存在 /sdcard/dcim/pic.jpg 中
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/dcim/pic.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivity(intent, 0);
14 尋找Market上某AP, 需要package名稱 Uri uri = Uri.parse("market://search?q=pname:com.tsots.contacts");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

沒有留言:

張貼留言