Android 常用代码工具

来源:互联网 发布:元数据和数据的区别 编辑:程序博客网 时间:2024/06/01 08:38

1.如何在应用中打开已安装应用

//-----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名   Intent intent=new Intent();       //打开大众点评          intent.setComponent(new ComponentName("com.dianping.v1","com.dianping.v1.MainActivity"));    startActivity(intent);   
2.判断路径是否可以读写
// 判断路径是否可以读写private boolean CheckeDirRW(String strpath){File file = new File(strpath);// 判断文件夹是否存在,如果不存在则创建文件夹if (!file.exists() || !file.canRead() || !file.canWrite()){return false;}return true;}

3.显示信息
// 显示信息public void DisplayToast(String str){Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);toast.setGravity(Gravity.TOP, 0, 220);toast.show();}
4.写LOG
public void writeLog(String strlogline){// //Log.d("jun", Logpath);String strline = strlogline;strline += "\n";// //Log.d("jun", strline);FileWriter fw = null;try{fw = new FileWriter(Logpath, true);fw.append(strline);fw.close();}catch (IOException e){e.printStackTrace();// //Log.d("jun", e.getMessage());}}


原创粉丝点击