摘要: 1:服务端代码如下2:Android Client端。(1):activity_main.xml (2):UIHelper.java为了更方便使用Toast,所以在这里自定义了一个类,进行了简单的封装。public class UIHelper { private Context context=null; public UIHelper(Context context){ this.context=context; } public void ShortToast(St... 阅读全文
posted @ 2013-10-12 12:57 yshy 阅读(1016) 评论(0) 推荐(0)
摘要: service是运行在后台的服务,你可以启动一个服务Service来播放音乐,或者记录你地理信息位置的改变,或者启动一个服务来运行并一直监听某种动作。接下来分析一下service 的生命周期:1:actiivty_main.xml 2:ServiceDemo.javapublic class ServiceDemo extends Service{ private static final String TAG="ServiceDemo"; public static final String ACTION="com.yan... 阅读全文
posted @ 2013-10-12 09:01 yshy 阅读(244) 评论(0) 推荐(0)
摘要: 1:包结构如下:2:MyService.javapublic class MyService { public int add(int a,int b){ return a+b; } public int cal(int a,int b){ return a*b; }}3:MyServiceTest.javapublic class MyServiceTest extends AndroidTestCase { MyService ms=new MyService(); public void testAdd(){ int sum=ms.add(1, 2); Assert.asse... 阅读全文
posted @ 2013-10-11 12:04 yshy 阅读(240) 评论(0) 推荐(0)
摘要: 1:activity_main.xml 2:文件操作类:FileService.javapublic class FileService { private Context context=null; public FileService(Context context){ this.context=context; } //save file public void saveFile(String filename,String content) throws Exception{ FileOutputStream... 阅读全文
posted @ 2013-10-11 11:11 yshy 阅读(1842) 评论(0) 推荐(0)
摘要: /** * 检查是否安装SD卡 * @return */ public static boolean checkSaveLocationExists() { String sDCardStatus = Environment.getExternalStorageState(); boolean status; if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) { status = true; } else status = false; return status; }} 阅读全文
posted @ 2013-10-11 09:43 yshy 阅读(314) 评论(0) 推荐(0)
摘要: /** * 检测网络是否可用 * @return */ public boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.isConnectedOrConnecting(); } 阅读全文
posted @ 2013-10-11 09:08 yshy 阅读(206) 评论(0) 推荐(0)
摘要: /** * 获取当前网络类型 * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络 */ public int getNetworkType() { int netType = 0; ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(... 阅读全文
posted @ 2013-10-11 09:07 yshy 阅读(383) 评论(0) 推荐(0)
摘要: 1:首先在res/anim/文件夹下建立动画xml文件。2:在java代码中对UI控件使用动画。//加载动画 Animation myAnim=AnimationUtils.loadAnimation(this, R.anim.my_anim);//对UI控件开启动画 tvShow.startAnimation(myAnim);3:说明Android的animation由四种类型组成在XML文件中:alpha渐变透明度动画效果scale渐变尺寸伸缩动画效果translate画面转换位置移动动画效果rotate画面转移旋转动画效果在Java 源码中定义了相应的类,可以使用这些类的方法来获取和.. 阅读全文
posted @ 2013-10-11 08:29 yshy 阅读(288) 评论(0) 推荐(0)
摘要: 1:~$ vim .bashrc2:在打开的.bashrc文件中加入:alias adt='./adt-bundle-linux-x86-20130729/eclipse/eclipse'3:保存退出。4:注销用户重新登录。5:打开终端输入:~$ adt 阅读全文
posted @ 2013-10-11 07:19 yshy 阅读(198) 评论(0) 推荐(0)
摘要: Info:startActivty 与 startActivityForResult区别(1):startActivity 启动了其他Activity之后不会再回调过来,此时启动者与被启动者在启动后没有联系了。(2):startActivityForResult 可以进行回调,之后有联系。1:activity_main.xml 2:MainActivity.java 1 public class MainActivity extends Activity { 2 private Button btn1=null; 3 private TextView tvShow... 阅读全文
posted @ 2013-10-10 15:35 yshy 阅读(254) 评论(0) 推荐(0)