adb pull /data/data/com.example.sample ./sample/
從本機上傳檔案
adb push ./sample/ /sdcard/sample/
當然也可以用DDMS,但是有時候指令是方便許多~
參考
private void bindAllApps() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);
sortappInstalledTime(mAllApps);
}
public void sortappInstalledTime(List<ResolveInfo> mAllApps2) {
Collections.sort(mAllApps2, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
ResolveInfo p1 = (ResolveInfo) o1;
ResolveInfo p2 = (ResolveInfo) o2;
Date d1 = getInstallTime(p1.activityInfo.packageName);
Date d2 = getInstallTime(p2.activityInfo.packageName);
if (d1 != null && d2 != null) {
if (d1.after(d2)) {
return -1;
} else if (d1 == d2) {
return 0;
} else {
return 1;
}
} else {
return 1;
}
}
});
}
public Date getInstallTime(String packageName) {
PackageManager pkgMgt = this.getPackageManager();
return firstNonNull(installTimeFromPackageManager(pkgMgt, packageName),
apkUpdateTime(pkgMgt, packageName));
}
private Date apkUpdateTime(PackageManager packageManager, String packageName) {
try {
android.content.pm.ApplicationInfo info = packageManager
.getApplicationInfo(packageName, 0);
File apkFile = new File(info.sourceDir);
return apkFile.exists() ? new Date(apkFile.lastModified()) : null;
} catch (NameNotFoundException e) {
return null; // package not found
}
}
private Date installTimeFromPackageManager(PackageManager packageManager,
String packageName) {
try {
PackageInfo info = packageManager.getPackageInfo(packageName, 0);
Field field = PackageInfo.class.getField("firstInstallTime");
long timestamp = field.getLong(info);
return new Date(timestamp);
} catch (NameNotFoundException e) {
return null; // package not found
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (SecurityException e) {
}
// field wasn't found
return null;
}
private Date firstNonNull(Date... dates) {
for (Date date : dates)
if (date != null)
return date;
return null;
}
public void sortappByUid(List<ResolveInfo> mAllApps2) {
Collections.sort(mAllApps2, new Comparator<ResolveInfo>() {
public int compare(ResolveInfo o1, ResolveInfo o2) {
ResolveInfo r1 = (ResolveInfo) o1;
ResolveInfo r2 = (ResolveInfo) o2;
int uid1 = r1.activityInfo.applicationInfo.uid;
int uid2 = r2.activityInfo.applicationInfo.uid;
if (uid1>=uid2) {
return -1;
} else if (r1 == r2) {
return 0;
} else {
return 1;
}
}
});
}