简体   繁体   中英

resolveActivity(getPackageManager()) != null returns null

It returns null for default sms and call apps while running from my android studio, but worked when executed with someone else's, From my android studio it is executing the else block and if I put startActivity(intent) without if statement it executes

callDial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(userData.get(position).getContNum()!= null)
            {
                Intent callIntent = new Intent(Intent.ACTION_DIAL);
                String strMobileNo = String.format("tel:%s",
                        userData.get(position).getContNum());
                //String m = "tel: " + txtCALL.getText().toString();
               /* Log.d("STR MOBILE NO : " , strMobileNo);*/

                callIntent.setData(Uri.parse(strMobileNo));
                //startActivity(callIntent);
                if(callIntent.resolveActivity(context.getPackageManager()) != null)
                    context.startActivity(callIntent);
                else
                    Log.v("ERROR : " , "Call Activity Cannot be started");
            }
        }
    });

While on my android studio this block of code is executing the if block ie the direct call one without opening default app. . .

callDirect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!userData.get(position).getContNum().isEmpty()) {
                String mobileNo = String.format("tel: %s", userData.get(position).getContNum());
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse(mobileNo));
                if (callIntent.resolveActivity(context.getPackageManager()) != null) {
                    context.startActivity(callIntent);
                } else
                    Log.d("CALL ERROR ", "CALL CANNOT BE INITIATED");
            }
        }
    });

On Android 11 and later you need to declare a queries element in your manifest to have visibility to other packages with methods like resolveActivity() . See: https://developer.android.com/training/basics/intents/package-visibility

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM