博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开源项目之Android Ecclesia(短信应用)
阅读量:6671 次
发布时间:2019-06-25

本文共 4533 字,大约阅读时间需要 15 分钟。

Ecclesia 是一个 Android 的应用程序,该用户程序在手机接收到短信时会自动通过表单提交的方式将短信息发送到指定的URL。

项目如图:

源码简单移动,就直接贴出主要源码了!

 

ActivityEcclesia.java
private void onInit() {		try {			String[] projection = new String[] { People._ID, People.NAME, };			Uri mContacts = People.CONTENT_URI;			// 读取联系人			Cursor managedCursor = managedQuery(mContacts, projection, // Which																		// columns																		// to																		// return					null, // WHERE clause; which rows to return (all rows)					null, // WHERE clause selection arguments (none)					People.NAME + " ASC"); // Order-by clause (ascending by											// name)			Cursor cur = managedCursor;			if (cur.moveToFirst()) {				String id;				String name;				do {					// Get the field values					id = cur.getString(cur.getColumnIndex(People._ID));					name = cur.getString(cur.getColumnIndex(People.NAME));					if (name.equals(this.getString(R.string.sms_prefix)) != true) {						continue;					}					String where = Contacts.Organizations.PERSON_ID + " == "							+ id + "";					// URL Address					Cursor addressCursor = managedQuery(							Contacts.ContactMethods.CONTENT_URI, null, where,							null, null);					int postalAddress = addressCursor							.getColumnIndexOrThrow(Contacts.ContactMethodsColumns.DATA);					address = "";					if (addressCursor.moveToFirst()) {						address = addressCursor.getString(postalAddress);					}					addressCursor.close();					// Login Information					Cursor orgCursor = managedQuery(							Contacts.Organizations.CONTENT_URI, null, where,							null, null);					if (orgCursor.moveToFirst()) {						do {							if (orgCursor									.getString(											orgCursor													.getColumnIndexOrThrow(Contacts.OrganizationColumns.COMPANY))									.equals(this											.getString(R.string.key_user_id)) == true) {								userId = orgCursor										.getString(orgCursor												.getColumnIndexOrThrow(Contacts.OrganizationColumns.TITLE));							}							if (orgCursor									.getString(											orgCursor													.getColumnIndexOrThrow(Contacts.OrganizationColumns.COMPANY))									.equals(this											.getString(R.string.key_user_pass)) == true) {								userPass = orgCursor										.getString(orgCursor												.getColumnIndexOrThrow(Contacts.OrganizationColumns.TITLE));							}						} while (orgCursor.moveToNext());					}					orgCursor.close();					// AndroidManifest.xml 
TextView tv; tv = (TextView) this.findViewById(R.id.textView); tv = new TextView(this); tv.setText("[" + this.getString(R.string.sms_prefix) + "] " + id + " " + name + " " + address + " " + userId + " " + userPass); setContentView(tv); WebView webView = new WebView(this); setContentView(webView); if (webView != null) { // js调用 // http://host/index.php
webView.setWebChromeClient(new WebChromeClient()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSavePassword(false); webView.getSettings().setSaveFormData(false); webView.loadDataWithBaseURL(address, "
", "text/html", "utf-8", "http://www.google.com/"); webView.requestFocus(); } break; } while (cur.moveToNext()); } } catch (Exception e) { java.lang.System.out.println(e.getMessage()); } }

 

 

IntentReceiver.java
public class IntentReceiver extends BroadcastReceiver { //短信的接收广播	@Override	public void onReceive(Context context, Intent intent) {		// TODO Auto-generated method stub		if (intent.getAction()				.equals("android.provider.Telephony.SMS_RECEIVED") == true) {			SmsMessage msg[] = getIntentMessages(intent);			for (int i = 0; i < msg.length; i++) {				String message = msg[i].getDisplayMessageBody();				if (message != null && message.length() > 0) {					if ((message.startsWith(R.string.sms_prefix + " ") == true)							|| (msg[i].getOriginatingAddress().equals("") != true)) {						Intent broadcast = new Intent(								"com.android.demo.WAKE_UP");						broadcast.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);						context.startActivity(new Intent(broadcast));					}				}				break;			}		}	}	private SmsMessage[] getIntentMessages(Intent intent) {		SmsMessage message[] = null;		Bundle bundle = intent.getExtras();		try {			Object pdus[] = (Object[]) bundle.get("pdus");			message = new SmsMessage[pdus.length];			for (int n = 0; n < pdus.length; n++) {				byte[] bytes = (byte[]) pdus[n];				message[n] = SmsMessage.createFromPdu(bytes);			}		} catch (Exception e) {			java.lang.System.out.println(e.toString());		}		return message;	}}

是不是很简单啊!~

 

 

你可能感兴趣的文章
JS实现AOP拦截方法调用
查看>>
文件上传
查看>>
移位操作发现的悲剧
查看>>
win10 nodejs指定ionic版本安装(npm方式)
查看>>
JumpServer跳板机
查看>>
mongodb 与 c++ 的配合使用
查看>>
ios 对齐属性
查看>>
[CDQ分治][Treap][树状数组]JZOJ 4419 Hole
查看>>
javascript -- 将数组转换为字符串:join()
查看>>
HDU - 1078 DP + 记忆化搜索
查看>>
Linux基础命令详解
查看>>
python 函数1
查看>>
WPF Step By Step 系列-Prism框架在项目中使用
查看>>
forms组件
查看>>
第十周进度条
查看>>
源码安装node8.11.1
查看>>
JAVA HTTP通信
查看>>
bootanimation 动画替换调试
查看>>
[LeetCode] Rectangle Overlap
查看>>
css3 box-sizing属性
查看>>