的Android设备上安装的应用程序拦截 [英] Interception of Installed Applications on android device
本文介绍了的Android设备上安装的应用程序拦截的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我包名称和放大器的名单;在数据库安装的应用程序的标签,现在我想安装的应用程序和数据库拦截。假设任何应用程序从设备上删除,然后我想在数据库更改。对于我使用广播接收器,但我的code不工作。
软件包管理系统PM = this.getPackageManager();
清单< ApplicationInfo> 。名单= getPackageManager()getInstalledApplications(PackageManager.PERMISSION_GRANTED);
对于(INT N = 0; N<则为list.size(); N ++){
Apps.add(list.get(n)的.loadLabel(下午)的ToString());
AppsP.add(list.get(n)的.packageName.toString());
Log.w(安装的应用程序,list.get(N).loadLabel(PM)的ToString());
Log.w(安装的应用程序包,list.get(N).packageName.toString());
...
在其他类 公共类PackageReceiver扩展广播接收器{ @覆盖
公共无效的onReceive(上下文的背景下,意图意图){
// TODO自动生成方法存根
如果(intent.getAction()。equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)){
。字符串added_package = intent.getData()的toString();
Log.i(PackageReceiver,包新增=+ added_package); }否则如果(intent.getAction()。equalsIgnoreCase(Intent.ACTION_PACKAGE_REMOVED)){
。字符串removed_package = intent.getData()的toString();
MyDBHelper DB =新MyDBHelper(背景);
Log.i(PackageReceiver,包删除=+ removed_package);
DB.open();
DB.deleteStmt = DB.db.compileStatement(QueryManager.ApplicationDelete);
DB.deleteStmt.bindString(1,removed_package);
DB.close(); }
任何帮助??
解决方案
intentAPP.addAction(Intent.ACTION_PACKAGE_ADDED);
intentAPP.addAction(Intent.ACTION_PACKAGE_CHANGED);
intentAPP.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
intentAPP.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentAPP.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentAPP.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentAPP.addAction(Intent.ACTION_PACKAGE_RESTARTED);//在数据库存储列表 对(INT I = 0; I&下; AppsP.size()及&放大器; I&下; Apps.size();我++){ DB.insertStmt.bindString(1,URLDe coder.de code(AppsP.get(I)));
DB.insertStmt.bindString(2,URLDe coder.de code(Apps.get(I)));
DB.insertStmt.bindString(3,1 +);
DB.insertStmt.bindString(4,假);
DB.insertStmt.executeInsert(); }//添加封装的通知
如果(intent.getAction()。equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)){
。字符串added_package = intent.getData()的toString();
Log.i(PackageReceiver,包新增=+ added_package);
意图Intent_add =新的Intent();
Intent_add.setClass(背景下,ServiceAppsAdd.class);
Intent_add.putExtra(PACKAGE_NAME,added_package.substring(8));
Intent_add.putExtra(状态,status_new);
context.startService(Intent_add);
I got the list of Package name & Label of installed application in database, Now I want to interception with installed application and database. Suppose any application delete from device then I want changes in Database. for that i am using broadcast receiver but my code not works.
PackageManager pm = this.getPackageManager();
List < ApplicationInfo > list = getPackageManager().getInstalledApplications(PackageManager.PERMISSION_GRANTED);
for (int n = 0; n < list.size(); n++) {
Apps.add(list.get(n).loadLabel(pm).toString());
AppsP.add(list.get(n).packageName.toString());
Log.w("Installed Applications", list.get(n).loadLabel(pm).toString());
Log.w("Installed Applications Package", list.get(n).packageName.toString());
...
In other class
public class PackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)) {
String added_package = intent.getData().toString();
Log.i("PackageReceiver", "Package Added = " + added_package);
} else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_REMOVED)) {
String removed_package = intent.getData().toString();
MyDBHelper DB = new MyDBHelper(context);
Log.i("PackageReceiver", "Package removed = " + removed_package);
DB.open();
DB.deleteStmt = DB.db.compileStatement(QueryManager.ApplicationDelete);
DB.deleteStmt.bindString(1, removed_package);
DB.close();
}
any help??
解决方案
intentAPP.addAction(Intent.ACTION_PACKAGE_ADDED);
intentAPP.addAction(Intent.ACTION_PACKAGE_CHANGED);
intentAPP.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
intentAPP.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentAPP.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentAPP.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentAPP.addAction(Intent.ACTION_PACKAGE_RESTARTED);
//for storing list in db
for (int i = 0; i < AppsP.size() && i < Apps.size(); i++) {
DB.insertStmt.bindString(1, URLDecoder.decode(AppsP.get(i)));
DB.insertStmt.bindString(2, URLDecoder.decode(Apps.get(i)));
DB.insertStmt.bindString(3, 1 + "");
DB.insertStmt.bindString(4, "false");
DB.insertStmt.executeInsert();
}
//adding package notification
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_ADDED)) {
String added_package = intent.getData().toString();
Log.i("PackageReceiver", "Package Added = " + added_package);
Intent Intent_add = new Intent();
Intent_add.setClass(context, ServiceAppsAdd.class);
Intent_add.putExtra("Package_Name", added_package.substring(8));
Intent_add.putExtra("Status", status_new);
context.startService(Intent_add);
这篇关于的Android设备上安装的应用程序拦截的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文