激活系统界面,清理应用的缓存
技术点:1、查看低版本的源码 sysyem→app→Settings.apk 反编译 2、判断当前操作系统的版本号: // 判断当前操作系统的版本号 // 4.1 16 // 4.2 17 // 2.2 8 // 2.3.1 9 // 2.3.3 10 // 2.1 7 // 判断当前操作系统的版本号 int sdkInt = Build.VERSION.SDK_INT; 手机版本,系统版本,sdk版本,android版本 |
目标:查找设置界面对应的Activity的action
ctrl+h settings_label_launcher <activity android:name="Settings"
android:label="@string/settings_label_launcher"
android:taskAffinity="com.android.settings"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
|
目标:查找这个界面的Activity对应的Action 1、ctrl+h 搜应用信息 <string name="application_info_label" msgid="5736524913065714880">"应用信息"</string> 2、继续ctrl+h 搜application_info_label 3、找到了对应的Activitiy的Action声明 <!-- Still need a top-level activity for showing app details. Aliasing
trick is so the code that is now a fragment can still be called
InstalledAppDetails. -->
<activity android:name=".applications.InstalledAppDetailsTop"
android:label="@string/application_info_label"
android:exported="true"
android:taskAffinity=""
android:parentActivityName="Settings$ManageApplicationsActivity">
</activity>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name=".applications.InstalledAppDetails"
android:label="@string/application_info_label"
android:exported="true"
android:targetActivity=".applications.InstalledAppDetailsTop">
<intent-filter>
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity-alias>
|
核心代码: // 3、扫描到的ListView的item的点击事件-点击就进入设置"应用信息"的界面
lv_clean_cache.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*<activity-alias android:name=".applications.InstalledAppDetails"
android:label="@string/application_info_label"
android:exported="true"
android:targetActivity=".applications.InstalledAppDetailsTop">
<intent-filter>
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity-alias>*/
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.addCategory(Intent.CATEGORY_DEFAULT);
String packageName = null;// 包名
Map<String, Long> map = cacheList.get(position);
for (Entry<String, Long> entry : map.entrySet()) {
packageName = entry.getKey();
}
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
});
|
问题:上面的代码在android2.3以后都可以运行,但在android2.2版本出现了问题 android2.2中对应的清理缓存的界面 11-21 08:06:39.664: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.VIEW cmp=com.android.settings/.InstalledAppDetails (has extras) } |
如何查看android低版本的源码? 1、选中android2.2的模拟器,File Explorer视图 然后进入sysyem→app→Settings.apk 2、然后反编译资源文件 apktool.bat d Settings.apk 3、然后在反编译的清单文件找到应用信息对应的Activity的Action <activity android:label="@string/application_info_label" android:name="InstalledAppDetails">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
</activity> 4、然后dex2jar.bat classes.dex 5、然后用jd-gui.exe读取源码,可以看到要设置的数据的名称 "pkg" Intent localIntent = getIntent(); String str1 = "pkg"; String str2 = localIntent.getStringExtra(str1); |
清理缓存高版本及低版本的解决方案: // 3、扫描到的ListView的item的点击事件-点击就进入设置"应用信息"的界面
lv_clean_cache.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*3-1 Android2.3后的应用信息界面的Action
* <activity-alias android:name=".applications.InstalledAppDetails"
android:label="@string/application_info_label"
android:exported="true"
android:targetActivity=".applications.InstalledAppDetailsTop">
<intent-filter>
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity-alias>*/
/*Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.addCategory(Intent.CATEGORY_DEFAULT);
String packageName = null;// 包名
Map<String, Long> map = cacheList.get(position);
for (Entry<String, Long> entry : map.entrySet()) {
packageName = entry.getKey();
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}*/
/*3-2 Android2.2的Action信息
* <activity android:label="@string/application_info_label" android:name="InstalledAppDetails">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
</activity>
String str1 = "pkg";
*/
/*Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addCategory("android.intent.category.VOICE_LAUNCH");
String packageName = null;// 包名
Map<String, Long> map = cacheList.get(position);
for (Entry<String, Long> entry : map.entrySet()) {
packageName = entry.getKey();
intent.putExtra("pkg", packageName);
startActivity(intent);
}*/ // 判断当前操作系统的版本号
// 4.1 16
// 4.2 17
// 2.2 8
// 2.3.1 9
// 2.3.3 10
// 2.1 7
// 判断当前操作系统的版本号
int sdkInt = Build.VERSION.SDK_INT; if (sdkInt >= 9) {// android2.3以上
Intent intent = new Intent();
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.addCategory(Intent.CATEGORY_DEFAULT);
String packageName = null;// 包名
Map<String, Long> map = cacheList.get(position);
for (Entry<String, Long> entry : map.entrySet()) {
packageName = entry.getKey();
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
} else {// android2.2及其以下
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addCategory("android.intent.category.VOICE_LAUNCH");
String packageName = null;// 包名
Map<String, Long> map = cacheList.get(position);
for (Entry<String, Long> entry : map.entrySet()) {
packageName = entry.getKey();
intent.putExtra("pkg", packageName);
startActivity(intent);
}
}
}
});
|