Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Issue with Samsung Note 8 running Android 7.1

$
0
0

My app invokes Call Phone intent. There is no problem with Marshmallow phones previously. But now on Note 8 I tried it for the first time. When I invoke the Call Phone intent I get the following Exception.Message.

Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } } from ProcessRecord{7dc990c 19695:Dates2Remember_XFAXU.Droid/u0a327} (pid=19695, uid=10327) with revoked permission android.permission.CALL_PHONE

A snip of my app's project properties is attached which shows that the Target version is set to 7.1 and the CALL_PHONE requirement is checked.

I am using dependency service. The dependant Android code is shown below. The following may be noted in this regard:

  1. Though Forms.Context is obsolete, it still works. However I have tried the other ways to set the Context also tried. The relevant code is commented below the Forms.Context usage.
  2. The error occurs at context.StartActivity(intent).

    using Android.Content;
    using Android.Telephony;
    using System;
    using System.Linq;
    using Xamarin.Forms;
    using Uri = Android.Net.Uri;

    [assembly: Dependency(typeof(PhoneDialer.Droid.PhoneDialer))]

    // For this to work ensure .Droid's Project Options -> Build
    // -> Android Application -> Required Permissions -> CallPhone
    // is checked.
    namespace PhoneDialer.Droid
    {
    public class PhoneDialer : IDialer
    {
    //Context context => Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity;

        // Dial the phone
        public bool DialFromDevice(string number, string displayName)
        {
            bool rtn_value = false;
    
            try
            {
                var context = Forms.Context;
                //Context context = Android.App.Application.Context;
                //var context = MyApp.Droid.MainActivity.instance;
    
                if (context != null)
                {
                    var intent = new Intent(Intent.ActionCall);
                    intent.SetData(Uri.Parse("tel:" + number));
    
                    if (IsIntentAvailable(context, intent))
                    {
                        context.StartActivity(intent);
                        rtn_value = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error: {0}", ex.Message);
                rtn_value = false;
            }
    
            return rtn_value;
        }
    
        // Checks if an intent can be handled.
        public static bool IsIntentAvailable(Context context, Intent intent)
        {
            var packageManager = context.PackageManager;
    
            var list = packageManager.QueryIntentServices(intent, 0)
                .Union(packageManager.QueryIntentActivities(intent, 0));
            if (list.Any())
                return true;
    
            TelephonyManager mgr = TelephonyManager.FromContext(context);
            return mgr.PhoneType != PhoneType.None;
        }
    }
    

    }

No issue with even Marshmallow simulator for VS. My Note 8 is still at API 25. It appears the project context is not passed on properly. Am I doing anything wrong?

Note: Unfortunately here if you employ multiple modes of formatting something will not presented correctly as required. Any suggestions to correct it, form myside, are welcome.


Viewing all articles
Browse latest Browse all 204402

Trending Articles