編輯:Android開發實例
發送短信:
- String body="this is sms demo";
- Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
- mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
- mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
- mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
- startActivity(mmsintent);
發送彩信:
- StringBuilder sb = new StringBuilder();
- sb.append("file://");
- sb.append(fd.getAbsoluteFile());
- Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));
- // Below extra datas are all optional.
- intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
- intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
- intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
- intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
- intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
- startActivity(intent);
廣播監聽短信並顯示內容:
AndroidManifest.xml中添加
- <receiver android:name=".receive">
- <intent-filter>
- <action android:name="android.provider.Telephony.SMS_RECEIVED" />
- </intent-filter>
- </receiver>
- <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
- <uses-permission android:name="android.permission.READ_SMS"></uses-permission>
再寫一個廣播監聽
- public class receive extends BroadcastReceiver
- {
- String receiveMsg = "";
- public void onReceive(Context context, Intent intent)
- {
- SmsMessage[] msg= null;
- if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
- {
- //StringBuilder buf = new StringBuilder();
- Bundle bundle = intent.getExtras();
- if (bundle != null) {
- Object[] pdusObj = (Object[]) bundle.get("pdus");
- msg= new SmsMessage[pdusObj.length];
- for (int i = 0; i<pdusObj.length; i++)
- msg[i] = SmsMessage.createFromPdu ((byte[]) pdusObj[i]);
- }
- for(int i = 0; i < msg.length; i++)
- {
- String msgTxt = msg[i].getMessageBody();
- if (msgTxt.equals("Testing!"))
- {
- Toast.makeText(context, "success!", Toast.LENGTH_LONG).show();
- return;
- }
- else
- {
- Toast.makeText(context, msgTxt, Toast.LENGTH_LONG).show();
- return;
- }
- }
- return;
- }
- }
繼上一篇介紹了如何使用Gallery控件之後,本文就來講一下Gallery 與ImageSwitcher的結合使用。本文所述實例代碼將實現一個簡單的浏覽圖片的功能
前言: 這個效果實現的原作者是國外一位大神。我在其基礎上測試,以及在代碼上加了不少注釋,以及局部修改。後面我有根據漫天飛舞雪花,實現下雨天場景的效
可以輕松地控制鈴聲音量和鈴聲配置文件,即:(無聲,震動,響亮等)在Android中。 Android提供了訪問這些控件AudioManager類。
組合模式定義: Compose objects into tree structures to represent part-whole hierarchies.