編輯:關於Android編程
今天講如何獲取手機短信
首先是AndroidMainfest裡面需要申請的權限:
// 設置所有短信
public void getMobileMessage(Intent m) {
final String SMS_URI_ALL = "content://sms/"; //所有短信
final String SMS_URI_INBOX = "content://sms/inbox"; //未發送短信
final String SMS_URI_SEND = "content://sms/sent"; //已發送短信
final String SMS_URI_DRAFT = "content://sms/draft"; //草稿箱
int count = 0;
StringBuilder smsBuilder = new StringBuilder();
try {
ContentResolver cr = m.getContentResolver();
String[] projection = new String[] { "_id", "address", "person",
"body", "date", "type" };
Uri uri = Uri.parse(SMS_URI_ALL);
Cursor cur = cr.query(uri, projection, null, null, "date desc");
if (cur.moveToFirst()) {
String name;
String phoneNumber;
String smsbody;
String date;
String type;
int nameColumn = cur.getColumnIndex("person");
int phoneNumberColumn = cur.getColumnIndex("address");
int smsbodyColumn = cur.getColumnIndex("body");
int dateColumn = cur.getColumnIndex("date");
int typeColumn = cur.getColumnIndex("type");
do {
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneNumberColumn);
smsbody = cur.getString(smsbodyColumn);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
Date d = new Date(Long.parseLong(cur.getString(dateColumn)));
date = dateFormat.format(d);
int typeId = cur.getInt(typeColumn);
if (typeId == 1) {
type = "接收";
} else if (typeId == 2) {
type = "發送";
} else {
type = "";
}
smsBuilder.append("[");
smsBuilder.append(name + ",");
smsBuilder.append(phoneNumber + ",");
smsBuilder.append(smsbody + ",");
smsBuilder.append(date + ",");
smsBuilder.append(type);
smsBuilder.append("] ");
if (smsbody == null)
smsbody = "";
count++;
} while (cur.moveToNext() && count < 10); //讀取默認排序的前10條短信
} else {
smsBuilder.append("no result!");
}
smsBuilder.append("getSmsInPhone has executed!");
} catch (SQLiteException ex) {
Log.d("SQLiteException in getSmsInPhone", ex.getMessage());
}
個人辛勤勞動成果,如有轉載,請注明出處,謝謝!
主要思想:將一個view設計成多層:背景層,含中獎信息等;遮蓋層,用於刮獎,使用關聯一個Bitmap的Canvas在該Bitmap上,使用它的canvas.drawPat
零、Gallery的使用回顧我們有時候在iPhone手機上或者Windows上面看到動態的圖片,可以通過鼠標或者手指觸摸來移動它,產生動態的圖片滾動效果,還可以根據你的點
Android調試工具 ADBADB Android Debug Bridge。ADB工具位於Android SDK安裝目錄的platform-tools子目錄。主要功能
一、加載過程動態展示動畫在APP的研發中,加載過程用動畫更改時間的消耗,增強用戶體驗。而有個更精細的加載過程動畫,會不斷從細節優化APP的體驗。且隨著APP與服務器交互的