本文搜集了一些自己经常用到的Android方面的奇淫技巧:
Log.v(String tag, String msg); //verbose类型日志,颜色为黑色 Log.d(String tag, String msg); //debug日志,颜色为蓝色 Log.i(String tag, String msg); //information日志,颜色为绿色 Log.w(String tag, String msg); //warn告警日志,颜色为橙色 Log.e(String tag, String msg); //error错误日志,颜色肯定为红色
import android.widget.Toast; Toast.makeText(this,"显示内容", Toast.LENGTH_SHORT).show();
import java.text.SimpleDateFormat; SimpleDateFOrmat formatter = new SimpleDateFormat("yyyy年MM月日 HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis()); // 获取当前时间 String str = formatter.formate(curDate);
public Location getLocation() { LocationManager locManger = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location loc = locManger.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (loc == null) { loc = locManger.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } return loc; }
开机自启动 <activity> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.HOME" /> </intent-filter> </activity> 权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>