后台运行:
adb logcat -v time -n 100 -r 10240 -f /sdcard/Logs/log &
查看进程:
ps logcat
参考链接:
后台运行:
adb logcat -v time -n 100 -r 10240 -f /sdcard/Logs/log &
查看进程:
ps logcat
参考链接:
转载自:Android退到后台与切到前台
最近开发了一款TV版app,主要功能是视频通话,所以要求机顶盒是一开机,就要把app打开,因为时刻有别人打过来。然后点击返回按钮,需要把app切到后台,但是app仍需要存活,需要收到消息。所以这里就设计到了app退到后台与切到前台的功能。
app退到后台
1.一般情况下,是启动Home页就可以实现这个功能,代码如下
Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent);
这里需要注意的是,如果Launcher和Home不是同一个,那就不能这么用。比如说华数机顶盒Launcher,启动第三方app都是从这里打开的。然后这里如果执行了上述代码,启动了Home,那就跳转到了Android系统的Home,与退到后台的效果有所出入了。
2.执行Activity#moveTaskToBack()
moveTaskToBack(false);
第一步:配置AndroidManifest
// 接收开机启动广播权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> // 广播接收器 <receiver android:name=".AlarmReceiver" > <intent-filter> <action android:name="com.android.test.ALARM" /> <action android:name="com.android.test.SETTING" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
安装应用
adb install -r test.apk
删除应用
adb uninstall com.android.test
启动应用
adb shell am start
-n "com.android.test/com.android.test.MainActivity"
-a android.intent.action.MAIN
-c android.intent.category.LAUNCHER
强制关闭应用 adb shell am force-stop com.android.test 注:给关闭状态的应用发送广播需要添加 FLAG_INCLUDE_STOPPED_PACKAGES 代码:intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); 命令:adb shell am broadcast -a com.android.test --include-stopped-packages
获取Android系统开机时间(秒):
Linux下:adb shell cat /proc/stat | grep btime
Windows下:adb shell cat /proc/stat | findstr btime
获取设备网络配置信息:
adb shell netcfg
参考链接:
adb shell am broadcast 参数
[-a <ACTION>]
[-p <PKG>]
[-d <DATA_URI>]
[-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--exclude-stopped-packages]
[--include-stopped-packages]
例如: adb shell am broadcast -a com.android.test -p com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true 说明:蓝色为key,红色为alue,分别为String类型,int类型,boolean类型
new Handler().postDelayed(new Runnable() { @Override public void run() { // 要执行的操作 } }, 1000 * 10); // 10秒后执行Runnable中的run方法
Linux下:adb shell ps | grep [apk包名]
Windows下:adb shell ps | findstr [apk包名]
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import io.kvh.media.amr.AmrDecoder; import io.kvh.media.amr.AmrEncoder; public class AmrUtil { private static final int[] amrEncodeMode = {4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200}; // amr 编码方式 private static final int AMR_FRAME_COUNT_PER_SECOND = 50; private static int mMode = 0; 继续阅读安卓AMR录音文件音量放大