找不到处理

时间:2016-01-06 05:09:20

标签: android permissions call

点击列表项<

时收到错误
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和intent过滤器

<?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>

4 个答案:

答案 0 :(得分:2)

你要

  

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

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

确保在AndroidManifest&amp; Intent.ACTION_CALL正确呼叫。

您可以分享 清单 。 你添加了吗?

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

答案 1 :(得分:0)

您可以尝试(您选择的文字格式必须为:tel:xxxxxxxxx)

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

请记住添加此权限:

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

答案 2 :(得分:0)

首先,由于您使用的是隐式意图,因此您无需在清单中指定调用权限。

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

  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.
  }

答案 3 :(得分:0)

重要的是要使电话呼叫数据格式如下class User(AbstractUser): is_medical = models.BooleanField(default=False) is_physiotherapist = models.BooleanField(default=False) is_patient = models.BooleanField(default=False) slug = models.SlugField(max_length=100, blank=True) photo = models.ImageField(upload_to='avatars', null = True, blank = True) def save(self, *args, **kwargs): user = super(User, self).save( *args, **kwargs) # Creating and user with medical, patient and physiotherapist profiles if self.is_medical and not MedicalProfile.objects.filter(user=self).exists()\ and self.is_patient and not PatientProfile.objects.filter(user=self).exists()\ and self.is_physiotherapist and not PhysiotherapistProfile.objects.filter(user=self).exists(): medical_profile=MedicalProfile(user=self).save() patient_profile=PatientProfile(user=self).save() physiotherapist_profile=PhysiotherapistProfile(user=self).save() #profile.save() # Creating and user with medical and patient profiles elif self.is_medical and not MedicalProfile.objects.filter(user=self).exists()\ and self.is_patient and not PatientProfile.objects.filter(user=self).exists(): medical_profile=MedicalProfile(user=self).save() patient_profile=PatientProfile(user=self).save() # Creating and user with medical and physiotherapist profiles elif self.is_medical and not MedicalProfile.objects.filter(user=self).exists()\ and self.is_physiotherapist and not PhysiotherapistProfile.objects.filter(user=self).exists(): medical_profile=MedicalProfile(user=self).save() physiotherapist_profile=PhysiotherapistProfile(user=self).save() # Creating and user with physiotherapist and patient profiles elif self.is_physiotherapist and not PhysiotherapistProfile.objects.filter(user=self).exists()\ and self.is_patient and not PatientProfile.objects.filter(user=self).exists(): physiotherapist_profile = PhysiotherapistProfile(user=self).save() patient_profile = PatientProfile(user=self).save() # Creating and user with medical profile elif self.is_medical and not MedicalProfile.objects.filter(user=self).exists(): profile = MedicalProfile(user=self) profile.save() # Creating and user with patient profile elif self.is_patient and not PatientProfile.objects.filter(user=self).exists(): profile = PatientProfile(user=self) profile.save() # Creating and user with physiotherapist profiles elif self.is_physiotherapist and not PhysiotherapistProfile.objects.filter(user=self).exists(): profile = PhysiotherapistProfile(user=self) profile.save() # We get the profiles user according with their type def get_medical_profile(self): medical_profile = None if hasattr(self, 'medicalprofile'): medical_profile=self.medicalprofile return medical_profile def get_patient_profile(self): patient_profile = None if hasattr(self, 'patientprofile'): patient_profile = self.patientprofile return patient_profile def get_physiotherapist_profile(self): physiotherapist_profile = None if hasattr(self, 'physiotherapistprofile'): physiotherapist_profile = self.physiotherapistprofile return physiotherapist_profile # We redefine the attributes (create db_table attribute) in class Meta to say to Django # that users will save in the same table that the Django default user model # https://github.com/django/django/blob/master/django/contrib/auth/models.py#L343 class Meta: db_table = 'auth_user' class MedicalProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) #active = models.BooleanField(default=True) name = models.CharField(max_length=64) class PatientProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) #active = models.BooleanField(default=True) name = models.CharField(max_length=64) class PhysiotherapistProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) #active = models.BooleanField(default=True) name = models.CharField(max_length=64) # Enter the username as slug field @receiver(post_save, sender = settings.AUTH_USER_MODEL) def post_save_user(sender, instance, **kwargs): slug = slugify(instance.username) User.objects.filter(pk=instance.pk).update(slug=slug) :)

tel:your_number