Android: detect when app is installed

前端 未结 2 1137
孤城傲影
孤城傲影 2020-12-17 04:33

I am trying to download an Android app from a server using the DownloadManager class, install it and then detect when the installation is completed. I am using

相关标签:
2条回答
  • 2020-12-17 04:58

    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);
    
    0 讨论(0)
  • 2020-12-17 05:01

    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 :)

    0 讨论(0)
提交回复
热议问题