編輯:關於 Android 程式設計
本節透過 Intent 機制與 SmsManager,介紹如何在 Android 中實現撥打電話與發送短信這兩個常見功能。
Intent:當找到與設置的 Intent 限制相同的 Activity 時,透過 startActivity() 就會啟動該 Activity。
電話撥號器:
intent.setAction("android.intent.action.CALL");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("tel:" + strmobile));
startActivity(intent);//方法內部會自動為 Intent 添加類別:android.intent.category.DEFAULT
短信發送器:
SmsManager manager = SmsManager.getDefault();
ArrayList<String> texts = manager.divideMessage(comtent);
for (String text : texts) {
manager.sendTextMessage(number, null, text, null, null);// 4和5參數分別為短信發送狀態,對方是否收到短信狀態;
}
Toast.makeText(getApplicationContext(),R.string.success,Toast.LENGTH_LONG).show();
Toast 對話框 // Toast.makeText(MainActivity.this, resId, duration);//內部類訪問外部類;
****************************************************************
findViewById(R.id.button);// 根據 id 查找顯示控件;
View.OnClickListener() {
@Override
public void onClick(View arg0) {
//arg0 就是被點擊的對象
}
}
@+id/button:在 R 文件的 id 內部類裡面添加一個 id 為 button 的常量,用該常量的值作為此控件的 id 值;
@android:表示訪問 android 包下的 R 文件;
@id/label:表示訪問 id 為 label 的文件(相對布局)。
單元測試:
繼承類:AndroidTestCase
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.hellokity" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
actual = function();
Assert.assertEquals(3,actual);//判斷 actual 是否為 3。
淺談Android應用保護(二):Anti-Analysis的常見方法與工具
此前談到,開發者為保護應用免遭分析與篡改,往往會把安全性寄託在某種機制上。可用於保護應用的機制有很多,效果與實現難度各異。本文聚焦其中一類——針對逆向工具的對抗(Anti
Android 中 Pull 與 SAX 解析 XML 的完整教學
本文將詳細講解在 Android 中解析 XML 的兩種常見方式:Pull 解析與 SAX 解析,供大家參考。 首先在專案中建立 assets 目錄(app/src/ma
Android View 滑動機制全解:scrollTo、Scroller 與 ViewDragHelper
只要提到 Android 裡的「滑動」,基本上都繞不開這三個傢伙:scrollTo、Scroller 和 ViewDragHelper。它們一個比一個高階,一個比一個好用
談談 Android 中 Context 的靈活使用技巧
大家好,今天想和大家聊聊 Android 裡 Context 的幾種用法。以前常有朋友在群組裡問我:如果在某個工具類的方法裡,或者在 View 當中需要使用 Contex