編輯:關於Android編程
SmsActivity.java
[java]
package com.example.lession01_sms;
import java.util.ArrayList;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SmsActivity extends Activity {
// 聲明控件對象
public Button btn_send;
public EditText edit_num;
public EditText edit_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 設置顯示的視圖(布局文件)
setContentView(R.layout.activity_sms);
btn_send = (Button) findViewById(R.id.button_send);
edit_num = (EditText) findViewById(R.id.edit_num);
edit_content = (EditText) findViewById(R.id.edit_content);
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/**
* 發送彩信
*/
// 獲取電話號碼
String phone_num = edit_num.getText().toString();
// 獲取發送內容
String phone_content = edit_content.getText().toString();
//創建意圖對象
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/1.jpg"));// uri為你的附件的uri
intent.putExtra("address", phone_num);//彩信發送目的號碼
intent.putExtra("exit_on_sent", true);
intent.putExtra("subject", "subject:I love you");//彩信的主題
intent.putExtra("sms_body", "content ::XXXX");//彩信中文字內容
intent.setType("image/*"); // 彩信附件類型
SmsActivity.this.startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sms, menu);
return true;
}
public void send(){
// 獲取控件對象
btn_send = (Button) findViewById(R.id.button_send);
edit_num = (EditText) findViewById(R.id.edit_num);
edit_content = (EditText) findViewById(R.id.edit_content);
// 為按鈕控件注冊事件
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// 獲取電話號碼
String phone_num = edit_num.getText().toString();
// 獲取發送內容
String phone_content = edit_content.getText().toString();
// 獲取短信管理器對象
SmsManager smsManager = SmsManager.getDefault();
// 意圖對象
PendingIntent pendingIntent = PendingIntent.getBroadcast(
SmsActivity.this, 0, new Intent(), 0);
//70分頁
ArrayList<String> contents = smsManager.divideMessage(phone_content);
for(String c :contents){
smsManager.sendTextMessage(phone_num, null, c, pendingIntent, null);
}
// 吐司效果
Toast.makeText(SmsActivity.this, "發送完畢", Toast.LENGTH_LONG)
.show();
}
});
}
/* public static void sendMMS(final Context context, String number,
String subject, String text, String imagePath, String audioPath) {
final MMSInfo mmsInfo = new MMSInfo(context, number, subject, text,
imagePath, audioPath);
final List<String> list = APNManager.getSimMNC(context);
new Thread() {
@Override
public void run() {
try {
byte[] res = MMSSender.sendMMS(context, list,
mmsInfo.getMMSBytes());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}*/
}
package com.example.lession01_sms;
import java.util.ArrayList;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SmsActivity extends Activity {
// 聲明控件對象
public Button btn_send;
public EditText edit_num;
public EditText edit_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 設置顯示的視圖(布局文件)
setContentView(R.layout.activity_sms);
btn_send = (Button) findViewById(R.id.button_send);
edit_num = (EditText) findViewById(R.id.edit_num);
edit_content = (EditText) findViewById(R.id.edit_content);
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/**
* 發送彩信
*/
// 獲取電話號碼
String phone_num = edit_num.getText().toString();
// 獲取發送內容
String phone_content = edit_content.getText().toString();
//創建意圖對象
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/1.jpg"));// uri為你的附件的uri
intent.putExtra("address", phone_num);//彩信發送目的號碼
intent.putExtra("exit_on_sent", true);
intent.putExtra("subject", "subject:I love you");//彩信的主題
intent.putExtra("sms_body", "content ::XXXX");//彩信中文字內容
intent.setType("image/*"); // 彩信附件類型
SmsActivity.this.startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sms, menu);
return true;
}
public void send(){
// 獲取控件對象
btn_send = (Button) findViewById(R.id.button_send);
edit_num = (EditText) findViewById(R.id.edit_num);
edit_content = (EditText) findViewById(R.id.edit_content);
// 為按鈕控件注冊事件
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// 獲取電話號碼
String phone_num = edit_num.getText().toString();
// 獲取發送內容
String phone_content = edit_content.getText().toString();
// 獲取短信管理器對象
SmsManager smsManager = SmsManager.getDefault();
// 意圖對象
PendingIntent pendingIntent = PendingIntent.getBroadcast(
SmsActivity.this, 0, new Intent(), 0);
//70分頁
ArrayList<String> contents = smsManager.divideMessage(phone_content);
for(String c :contents){
smsManager.sendTextMessage(phone_num, null, c, pendingIntent, null);
}
// 吐司效果
Toast.makeText(SmsActivity.this, "發送完畢", Toast.LENGTH_LONG)
.show();
}
});
}
/* public static void sendMMS(final Context context, String number,
String subject, String text, String imagePath, String audioPath) {
final MMSInfo mmsInfo = new MMSInfo(context, number, subject, text,
imagePath, audioPath);
final List<String> list = APNManager.getSimMNC(context);
new Thread() {
@Override
public void run() {
try {
byte[] res = MMSSender.sendMMS(context, list,
mmsInfo.getMMSBytes());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}*/
}
BottomBar BottomBar是Github上的一個開源框架,因為從1.3.3開始不支持fragments了,要自己配置,弄了很久,不管是app的fragm
1 背景前面分析那麼多系統源碼了,也該暫停下來休息一下,趁昨晚閒著看見一個有意思的需求就操練一下分析源碼後的實例演練—-自定義控件。這個實例很適合
本文主要是對Handler和消息循環的實現原理進行源碼分析,如果不熟悉Handler可以參見博文《詳解Android中Handler的使用方法》,裡面對Android為何
先來看看效果圖關鍵代碼1.監聽滾動事件首先要給listview添加setOnScrollListener監聽,注意這個監聽在recyclerView上是addOnScro