为什么文件的新ActionView具有黑色背景

时间:2018-11-06 03:38:26

标签: android xamarin

当我选择要打开文件的应用程序时,它将以黑色背景打开(与我的应用程序相同)。我希望它以默认格式打开,应该是带有黑色文本的白色背景。我的应用使用黑色背景。那背景会延续到新的Intent吗?接收到意图的PDF阅读器采用了发送应用程序的背景色,为什么?我该如何更改?

Android.Net.Uri uri = FileProvider.GetUriForFile(this, "myauthority", file);

            Intent target = new Intent(Intent.ActionView);
            target.SetDataAndType(uri, "application/pdf");
            target.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask | ActivityFlags.NoHistory);

            Intent intent = Intent.CreateChooser(target, "Open File");
            intent.AddFlags(ActivityFlags.GrantReadUriPermission);
            try
            {
                if (target.ResolveActivity(PackageManager) != null)
                {
                    StartActivity(intent);
                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("Unable to open PDF, check documents folder.", ex);
            }

1 个答案:

答案 0 :(得分:0)

删除CreateChooser意图,并仅从目标开始活动。

Android.Net.Uri uri = FileProvider.GetUriForFile(this, "myauthority", file);

            Intent target = new Intent(Intent.ActionView);
            target.SetDataAndType(uri, "application/pdf");
            target.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask | ActivityFlags.NoHistory | ActivityFlags.ClearTop | ActivityFlags.GrantReadUriPermission);

            //Intent intent = Intent.CreateChooser(target, "Open File");
            //intent.AddFlags(ActivityFlags.GrantReadUriPermission);
            try
            {
                if (target.ResolveActivity(PackageManager) != null)
                {
                    //StartActivity(intent);
                    StartActivity(target);
                }
            }
            catch (System.Exception ex)
            {
                Toast.MakeText(this, "Unable to open PDF, check documents folder.", ToastLength.Short);
                throw new System.Exception("Unable to open PDF, check documents folder.", ex);
            }