android.content.ActivityNotFoundException: No Activity found to handle Intent

來源:互聯網
上載者:User

標籤:android   style   blog   color   java   io   for   檔案   ar   

 

代碼如下:

    public void sendMessage(String number) {        if (TextUtils.isEmpty(number)) {            return;        }        Intent intent = new Intent(Intent.ACTION_SENDTO,                Uri.fromParts(Constants.SCHEME_SMS, number, null));        context.startActivity(intent);    }

異常資訊提示如下:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=sms:xxxxxxxxxxx } 

    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)

    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)

    at android.app.Activity.startActivityForResult(Activity.java:3424)

調查如下:

1,如果手機中沒有能傳送簡訊的app就會報出這樣的錯

2,手機中的能傳送簡訊的應用被關閉了(設定-->應用-->app-->關閉);

解決方案:為了避免有的手機沒有開啟相應檔案的app,在startActivity那裡做一個try catch

    public void sendMessage(String number) {        if (TextUtils.isEmpty(number)) {            return;        }        Intent intent = new Intent(Intent.ACTION_SENDTO,                Uri.fromParts(Constants.SCHEME_SMS, number, null));        try {            context.startActivity(intent);        } catch(ActivityNotFoundException exception) {            Toast.makeText(this, "no activity", Toast.LENGTH_SHORT).show();        }    }

or 調用系統方法判斷是否有對應的app

     public void sendMessage(String number) {        if (TextUtils.isEmpty(number)) {            return;        }        Intent intent = new Intent(Intent.ACTION_SENDTO,                Uri.fromParts(Constants.SCHEME_SMS, number, null));                PackageManager packageManager = getPackageManager();        List<ResolveInfo>applist = packageManager.queryIntentActivities(intent, 0);        if (applist == null || applist.isEmpty()) {            Toast.makeText(this, "no activity", Toast.LENGTH_SHORT).show();            return;        }        context.startActivity(intent);    }

 

android.content.ActivityNotFoundException: No Activity found to handle Intent

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.