当前位置: 编程技术>移动开发
本页文章导读:
▪搬动开发技术网站(社区)有哪些 移动开发技术网站(社区)有哪些?
Nokia (http://forum.nokia.com.cn/community.html)Apple Store(http://appshopper.com/)Windows Mobile (http://developer.windowsmobile.com/)Sun (http://java.sun.com/javame/index.jsp)Motor.........
▪ 程序 开机起步 程序 开机启动
开机启动[功能]就像Windows XP 那样开机启动 当系统启动完毕 就会运行你的程序[原理]1.android 有一个系统Broadcast 其action = "android.intent.action.BOOT_COMPLETED" 用途就是 通知系统已.........
▪ EditText 以内容监听器2 EditText 之内容监听器2
EditText 之内容监听
[功能]
以前写过通过 TextWatcher 监听 EditText 内容的改动 在知道那个之前 我都是通过 TextMonitor 监听其内容的更新 尽管现在其变得毫无意义 还是打算.........
[1]搬动开发技术网站(社区)有哪些
来源: 互联网 发布时间: 2014-02-18
移动开发技术网站(社区)有哪些?
Nokia (http://forum.nokia.com.cn/community.html)
Apple Store(http://appshopper.com/)
Windows Mobile (http://developer.windowsmobile.com/)
Sun (http://java.sun.com/javame/index.jsp)
Motorola (http://developer.motorola.com/)
中国移动开发者社区(http://dev.chinamobile.com/cmdn/bbs/index.php)
Sony Ericsson(https://developer.sonyericsson.com/site/zhcn/home/p_home.jsp)
BlackBerry(http://na.blackberry.com/eng/developers/)
Android(http://code.google.com/intl/zh-CN/android/adc/)
威锋社区(http://bbs.weiphone.com/)
魅族社区(http://bbs.meizu.com/)
CSDN (http://community.csdn.net)
Nokia (http://forum.nokia.com.cn/community.html)
Apple Store(http://appshopper.com/)
Windows Mobile (http://developer.windowsmobile.com/)
Sun (http://java.sun.com/javame/index.jsp)
Motorola (http://developer.motorola.com/)
中国移动开发者社区(http://dev.chinamobile.com/cmdn/bbs/index.php)
Sony Ericsson(https://developer.sonyericsson.com/site/zhcn/home/p_home.jsp)
BlackBerry(http://na.blackberry.com/eng/developers/)
Android(http://code.google.com/intl/zh-CN/android/adc/)
威锋社区(http://bbs.weiphone.com/)
魅族社区(http://bbs.meizu.com/)
CSDN (http://community.csdn.net)
[2] 程序 开机起步
来源: 互联网 发布时间: 2014-02-18
程序 开机启动
开机启动
[功能]
就像Windows XP 那样开机启动 当系统启动完毕 就会运行你的程序
[原理]
1.android 有一个系统Broadcast 其action = "android.intent.action.BOOT_COMPLETED" 用途就是 通知系统已经启动完毕
[做法]
1. 创建一个BroadcastReceiver 用来接收该Broadcast 在收到以后通过startActivity / startService 来启动目标应用
[代码]
1. UpNotificationListener 用于接收相应的Broadcast 然后启动相关应用
2. SystemUpApp 用于目标应用
That's all!
开机启动
[功能]
就像Windows XP 那样开机启动 当系统启动完毕 就会运行你的程序
[原理]
1.android 有一个系统Broadcast 其action = "android.intent.action.BOOT_COMPLETED" 用途就是 通知系统已经启动完毕
[做法]
1. 创建一个BroadcastReceiver 用来接收该Broadcast 在收到以后通过startActivity / startService 来启动目标应用
[代码]
1. UpNotificationListener 用于接收相应的Broadcast 然后启动相关应用
public class UpNotificationListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Intent i = new Intent(context, SystemUpApp.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
2. SystemUpApp 用于目标应用
public class SystemUpApp extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
That's all!
[3] EditText 以内容监听器2
来源: 互联网 发布时间: 2014-02-18
EditText 之内容监听器2
EditText 之内容监听
[功能]
以前写过通过 TextWatcher 监听 EditText 内容的改动 在知道那个之前 我都是通过 TextMonitor 监听其内容的更新 尽管现在其变得毫无意义 还是打算把之写下来
[原理]
* 2 个 thread:
写道
class TextUpdate extends Activity : 得到 EditText 的内容
class TextMonitor extends Service : 作为守护 负责监视 并返回EditText 的内容
class TextMonitor extends Service : 作为守护 负责监视 并返回EditText 的内容
* 原理
TextUpdate TextMonitor 1. Request <- 2. Reply -> 3. Notification <- 步骤: 1. TextMonitor 向 TextUpdate 发送 Message_Request 要求得到此刻 EditText 的内容 2. TextUpdate 收到 Message_Request 后 通过 EditText.getText() 得到此刻的字符串 并通过 Message_Reply 向 TextMonitor 发送 Broadcast 3. TextMonitor 在收到 Message_Reply 后 取出结果 并通过发送Broadcast 把结果通过 Message_Notification 返回结果 4. TextUpdat 在收到 Message_Notification 后 取出内容 然后刷新 TextView 内容
* 以上就是其全部原理
[代码 步骤]
1. 定义一些供 Broadcast & Message 用到的字符串
public class TextHelper { //broadcast definition public final static String Broadcast_Update = "Broadcast_Update"; public final static String Broadcast_Monitor = "Broadcast_Monitor"; //message definition public final static String Message_Request = "Message_Request"; public final static String Message_Reply = "Message_Reply"; public final static String Message_Notification = "Message_Notification"; }
2. 定义 TextMonitor 任务有:
写道
1. 发送 Message_Request
2. 发送 Message_Notification
3. 接收 Message_Reply
2. 发送 Message_Notification
3. 接收 Message_Reply
public void requestContent(){ Intent i = new Intent(TextHelper.Broadcast_Update); Bundle b = new Bundle(); b.putString(TextHelper.Message_Request, "Hello!"); i.putExtras(b); sendBroadcast(i); } public void notificationContent(String s){ Intent i = new Intent(TextHelper.Broadcast_Update); Bundle b = new Bundle(); b.putString(TextHelper.Message_Notification, s); i.putExtras(b); sendBroadcast(i); } public class MonitorMessageListenerHelper extends BroadcastReceiver { Context context; MonitorMessageListenerHelper listener; //construct public MonitorMessageListenerHelper(Context c){ context = c; //to instance it listener = this; } public void registerAction(String action){ IntentFilter filter = new IntentFilter(); filter.addAction(action); context.registerReceiver(listener,filter); } @Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub Bundle b = arg1.getExtras(); if(b.containsKey(TextHelper.Message_Reply)){ String string = b.getString(TextHelper.Message_Reply); if(! last.equals(string)){ notificationContent(string); last = string; } requestContent(); } } }
3. 定义 TextUpdate 任务有:
写道
1. 得到 EditText 的内容
2. 把得到的内容 在 TextView 中显示之
3. 把得到的字串 通过 Message_Reply 发送
4. 接收 Message_Request 后 得到目标内容
5. 接收 Message_Notification 并显示之
2. 把得到的内容 在 TextView 中显示之
3. 把得到的字串 通过 Message_Reply 发送
4. 接收 Message_Request 后 得到目标内容
5. 接收 Message_Notification 并显示之
public String getContent(){ return edit.getText().toString(); } public void displayContent(String s){ text.setText(s); } public void sendContent(String s){ Intent i = new Intent(TextHelper.Broadcast_Monitor); Bundle b = new Bundle(); b.putString(TextHelper.Message_Reply, s); i.putExtras(b); sendBroadcast(i); } public class UpdateMessageListenerHelper extends BroadcastReceiver { Context context; UpdateMessageListenerHelper listener; //construct public UpdateMessageListenerHelper(Context c){ context = c; //to instance it listener = this; } public void registerAction(String action){ IntentFilter filter = new IntentFilter(); filter.addAction(action); context.registerReceiver(listener,filter); } @Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub Bundle b = arg1.getExtras(); if(b.containsKey(TextHelper.Message_Request)){ sendContent(getContent()); } else if(b.containsKey(TextHelper.Message_Notification)){ String string = b.getString(TextHelper.Message_Notification); displayContent(string); } } }
4. emulator 运行截图:
5. 其实程序不太完善 缺失下面功能:
* TextMonitor 会始终运行 即使 EditText 没有焦点 有时间再改下!
done!
最新技术文章: