【问题标题】:no activity found to handle没有发现要处理的活动
【发布时间】:2016-01-06 05:09:19
【问题描述】:

点击列表项时出现错误

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    String selected =((TextView)view.findViewById(R.id.no)).getText().toString();
                    Toast toast=Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT);
                    toast.show();

                    try {
                        Intent in=new Intent(Intent.ACTION_CALL,Uri.parse(selected));
                        startActivity(in);
                    } catch (SecurityException e) {
                        Log.e("PERMISSION_EXCEPTION","PERMISSION_NOT_GRANTED");
                    }
}

错误是我在 Logcat 中收到的消息

01-06 10:37:19.091 19537-19537/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.example.sairamkrishna.myapplication, PID: 19537
                                                   android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=1234 567 89 }
                                                       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1856)
                                                       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1552)

*这里的清单文件我添加了权限和 MainActivity 和意图过滤器

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sairamkrishna.myapplication">
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 至少发布您的问题或 logcat。
  • 如果权限问题添加“
  • 确保在清单中添加活动

标签: android permissions call


【解决方案1】:

你得到了

android.content.ActivityNotFoundException:找不到要处理的活动 意图 { act=android.intent.action.CALL dat=1234 567 89 }

所有活动都必须在 AndroidManifest.xml 中声明。没有声明,ActivityNotFoundException 会被抛出。

确保在 AndroidManifest 中添加活动 & Intent.ACTION_CALL 正确调用。

您可以分享您的清单。 这个是你加的吗?

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

【讨论】:

  • 不,这是点击的问题,如果我删除意图,它工作正常。
  • @SairamkrishnaMammahe 好吧好吧。继续前进。
【解决方案2】:

你可以试试(你选择的文字必须是格式:tel:xxxxxxxxx)

 Intent in = new Intent(Intent.ACTION_DIAL,Uri.parse(selected));
                    startActivity(in);

记得添加这个权限:

<uses-permission android:name="android.permission.CALL_PHONE" />

【讨论】:

    【解决方案3】:

    首先由于使用的是隐式intent,所以不需要在manifest中指定调用权限。

    每当您调用任何隐式意图时,如果它没有找到任何可以执行给定操作的匹配活动,则会发生此异常。 您可以使用以下代码来处理。

      Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse(selected));
      List<ResolveInfo> list=new  PackageManager().queryIntentActivities(intent ,0);
      if(list.size()>0){
       Intent chooser = Intent.createChooser(intent, "title");
       startActivity(chooser);
      }else{
      //Show toast or alert saying no activities available to perform specified action.
      }
    

    【讨论】:

      【解决方案4】:

      重要的是让电话数据格式是这样的tel:your_number :)

       Intent in=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+selected));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-22
        • 1970-01-01
        • 2021-11-24
        • 1970-01-01
        • 2011-08-18
        • 2013-08-24
        相关资源
        最近更新 更多