運用手機多媒體
1.通知 Notification
使用步驟:
1.首先須要一個 NotificationManager 來對通知進行管理,能夠調用 Context 的getSystemService()方法獲取到
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);android
2.建立一個 Notification 對象,這個對象用於存儲通知所需的各類信息,咱們可使用它的有參構造函數來進行建立
Notification notification = new Notification(圖標, 瞬時內容, 建立時間);ide
3.建立好了 Notification 對象後,咱們還須要對通知的佈局進行設定,
這裏只須要調用Notification 的 setLatestEventInfo()方法就能夠給通知設置一個標準的佈局。
notification.setLatestEventInfo(context, 標題, 通知正文, null);函數
4. 只須要調用 NotificationManager 的 notify()方法就可讓通知顯示出來了。
manager.notify(惟一ID, notification);佈局
2.PendingIntent :
PendingIntent 從名字上看起來就和 Intent 有些相似, 它們之間也確實存在着很多共同點。
好比它們均可以去指明某一個「意圖」 ,均可以用於啓動活動、啓動服務以及發送廣播等。
不一樣的是,Intent 更加傾向於去當即執行某個動做,而 PendingIntent 更加傾向於在某個合適
的時機去執行某個動做。因此,也能夠把 PendingIntent簡單地理解爲延遲執行的 Intent。對象
3.短信
1.接收短信:
1.監聽短信接收系統廣播android.provider.Telephony.SMS_RECEIVED
2.在BroadcastReceiver子類的onReceive去解析短信內容
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object[] pdus = (Object[]) bundle.get("pdus"); // 提取短信消息
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
String address = messages[0].getOriginatingAddress(); // 獲取發送方號碼
String fullMessage = "";
for (SmsMessage message : messages) {
fullMessage += message.getMessageBody(); // 獲 取短信內容get
}
sender.setText(address);
content.setText(fullMessage);
}
2.攔截短信
1.系統發出的短信廣播是一條有序廣播,所以先設置接收的優先級再調用abortBroadcast();攔截短信便可io
3.發送短信
1.getDefault()方法獲取到 SmsManager的實例,而後再調用它的 sendTextMessage()方法就能夠
去發送短信了。sendTextMessage()方法接收五個參數,其中第一個參數用於指定接收人的手
機號碼,第三個參數用於指定短信的內容,其餘的幾個參數咱們暫時用不到,直接傳入 null就能夠了。
2.設置權限
<uses-permission android:name="android.permission. SEND_SMS" />ast
4.調用攝像頭
test