Android(安卓)Phone Application Development(Part 1)
16lz
2021-01-25
初步完成sample ap如附檔,第一個欄位為顯示業者名稱,第二欄位是電話號碼,下面為撥號鍵,其中主要是intent的使用。Intent 應該算是 Andorid 中特有的東西。你可以在 Intent 中,指定要應用程式執行的動作 (view, edit, dial),以及應用程式執行該動作時,所需要的資料。都指定好後,只要透過 startActivity(),Android 系統會自動尋找,最符合你指定要求的應用程式,並喚起執行該應用程式。以下為網路上找到的Sample code:顯示網頁
- Uriuri=Uri.parse("http://google.com");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
顯示地圖
- Uriuri=Uri.parse("geo:38.899533,-77.036476");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
- //其他geoURI範例
- //geo:latitude,longitude
- //geo:latitude,longitude?z=zoom
- //geo:0,0?q=my+street+address
- //geo:0,0?q=business+near+city
- //google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
路徑規劃
- Uriuri=Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
- //wherestartLat,startLng,endLat,endLngarealongwith6decimalslike:50.123456
撥打電話
- //叫出撥號程式
- Uriuri=Uri.parse("tel:0800000123");
- Intentit=newIntent(Intent.ACTION_DIAL,uri);
- startActivity(it);
- //直接打電話出去
- Uriuri=Uri.parse("tel:0800000123");
- Intentit=newIntent(Intent.ACTION_CALL,uri);
- startActivity(it);
- //用這個,要在AndroidManifest.xml中,加上
- //<uses-permissionid="android.permission.CALL_PHONE"/>
傳送 SMS/MMS
- //叫起簡訊程式
- Intentit=newIntent(Intent.ACTION_VIEW);
- it.putExtra("sms_body","TheSMStext");
- it.setType("vnd.android-dir/mms-sms");
- startActivity(it);
- //傳送簡訊
- Uriuri=Uri.parse("smsto:0800000123");
- Intentit=newIntent(Intent.ACTION_SENDTO,uri);
- it.putExtra("sms_body","TheSMStext");
- startActivity(it);
- //傳送MMS
- Uriuri=Uri.parse("content://media/external/images/media/23");
- Intentit=newIntent(Intent.ACTION_SEND);
- it.putExtra("sms_body","sometext");
- it.putExtra(Intent.EXTRA_STREAM,uri);
- it.setType("image/png");
- startActivity(it);
傳送 Email
- Uriuri=Uri.parse("mailto:xxx@abc.com");
- Intentit=newIntent(Intent.ACTION_SENDTO,uri);
- startActivity(it);
- Intentit=newIntent(Intent.ACTION_SEND);
- it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");
- it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
- it.setType("text/plain");
- startActivity(Intent.createChooser(it,"ChooseEmailClient"));
- Intentit=newIntent(Intent.ACTION_SEND);
- String[]tos={"me@abc.com"};
- String[]ccs={"you@abc.com"};
- it.putExtra(Intent.EXTRA_EMAIL,tos);
- it.putExtra(Intent.EXTRA_CC,ccs);
- it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
- it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
- it.setType("message/rfc822");
- startActivity(Intent.createChooser(it,"ChooseEmailClient"));
- //傳送附件檔
- Intentit=newIntent(Intent.ACTION_SEND);
- it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
- it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
- sendIntent.setType("audio/mp3");
- startActivity(Intent.createChooser(it,"ChooseEmailClient"));
播放多媒體
- Intentit=newIntent(Intent.ACTION_VIEW);
- Uriuri=Uri.parse("file:///sdcard/song.mp3");
- it.setDataAndType(uri,"audio/mp3");
- startActivity(it);
- Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
Market 相關
- //尋找某個應用程式
- Uriuri=Uri.parse("market://search?q=pname:pkg_name");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
- //wherepkg_nameisthefullpackagepathforanapplication
- //顯示某應用程式詳細畫面
- Uriuri=Uri.parse("market://details?id=app_id");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- startActivity(it);
- //whereapp_idistheapplicationID,findtheID
- //byclickingonyourapplicationonMarkethome
- //page,andnoticetheIDfromtheaddressbar
Uninstall 應用程式
- Uriuri=Uri.fromParts("package",strPackageName,null);
- Intentit=newIntent(Intent.ACTION_DELETE,uri);
- startActivity(it);
安裝 APK 檔
- Uriuri=Uri.parse("url_of_apk_file");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);
- it.setData(uri);
- it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- it.setClassName("com.android.packageinstaller",
- "com.android.packageinstaller.PackageInstallerActivity");
- startActivity(it);
- //makesuretheurl_of_apk_fileisreadableforallusers
更多相关文章
- Android(安卓)实现文件分享功能(共享多个文件)
- Android(安卓)framework analysis
- android中使用javamail发送邮件附件
- android 原生 电子邮件 应用 发送邮件附带 中文名附件时 附件名
- Android(安卓)Series: GET, POST and Multipart POST 请求
- PopupWindow 展开后点击返回键无效?
- android pop3与imap方式接收邮件(javamail)
- Android中为edittext预设文字(使用hint)
- 电脑无法安装Android设备驱动