Android: detect when app is installed

让人想犯罪 __ 提交于 2019-11-30 16:30:01

I solved my problem, I added

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");

before the line :

registerReceiver(installReceiver, intentFilter);

You can try the code below. This way you can get all activities that can be called by an intent and if you know the activity name and it is present in list retrieved by queryIntentActivities()..you know it is installed.

public void callQrScan()
    {
    Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");    

    if(isCallable(intent1)== true){



    Context context = getApplicationContext();
    CharSequence text = "Scan Niet Gelukt";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
    }
    else{
        Context context = getApplicationContext();
        CharSequence text = "Scan Niet Gelukt";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }


    Button tempbutton = (Button)findViewById(R.id.Button03);

    tempbutton.setOnClickListener(new OnClickListener()
    {
        public void onClick(final View v)
    {
                callQrScan();
    }
    });

    }

    private boolean isCallable(Intent intent1) {  
                List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent1,   
            PackageManager.MATCH_DEFAULT_ONLY);  
        if(list.size() > 0)
                return true ;  
        else
            return false;

    }

Hope it helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!