简体   繁体   English

resolveActivity(getPackageManager()) != null 返回 null

[英]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它返回 null 用于默认短信并在从我的 android 工作室运行时调用应用程序,但是在与其他人的工作室一起执行时工作,从我的 android 工作室(它正在执行没有 else start if 语句并执行 if IActivity)

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.在我的 android 工作室中,这段代码正在执行 if 块,即直接调用一个而不打开默认应用程序。 . . . .

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() .在 Android 11 及更高版本上,您需要在清单中声明一个queries元素,以便使用resolveActivity()等方法对其他包具有可见性。 See: https://developer.android.com/training/basics/intents/package-visibility请参阅: https://developer.android.com/training/basics/intents/package-visibility

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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