Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var util = new AndroidPlatformUtils(ApplicationContext);

            PlatformUtils.Instance = util;

            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            streamerListView                = FindViewById <ListView>(Resource.Id.streamerListView);
            leftTimeTextView                = FindViewById <TextView>(Resource.Id.leftTimeTextView);
            streamerListView.ItemClick     += StreamerListView_ItemClick;
            streamerListView.ItemLongClick += StreamerListView_ItemLongClick;

            stopButton = FindViewById <Button>(Resource.Id.stop_button);
            helpButton = FindViewById <Button>(Resource.Id.help_button);

            stopButton.Click += StopButton_Click;
            helpButton.Click += HelpButton_Click;
        }
Example #2
0
        private void SetNotifySoundPathWithUri(Android.Net.Uri uri)
        {
            bool isKitKat = Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat;

            if (isKitKat && DocumentsContract.IsDocumentUri(this, uri))
            {
                // ExternalStorageProvider
                if (isExternalStorageDocument(uri))
                {
                    string docId = DocumentsContract.GetDocumentId(uri);

                    char[]   chars = { ':' };
                    string[] split = docId.Split(chars);
                    string   type  = split[0];

                    if ("primary".Equals(type, StringComparison.OrdinalIgnoreCase))
                    {
                        streamerData.NotifySoundPath = Android.OS.Environment.ExternalStorageDirectory + "/" + split[1];
                        return;
                    }
                }
                // DownloadsProvider
                else if (isDownloadsDocument(uri))
                {
                    var id = DocumentsContract.GetDocumentId(uri);

                    if (id != null && id.StartsWith("raw:"))
                    {
                        streamerData.NotifySoundPath = id.Substring(4);
                        return;
                    }

                    String[] contentUriPrefixesToTry = new String[] {
                        "content://downloads/public_downloads",
                        "content://downloads/my_downloads",
                        "content://downloads/all_downloads"
                    };

                    foreach (String contentUriPrefix in contentUriPrefixesToTry)
                    {
                        Uri contentUri = ContentUris.WithAppendedId(Uri.Parse(contentUriPrefix), long.Parse(id));
                        try
                        {
                            String path = getDataColumn(this, contentUri, null, null);
                            if (path != null)
                            {
                                streamerData.NotifySoundPath = path;
                                return;
                            }
                        }
                        catch (Exception e) { }
                    }

                    var builder = new AlertDialog.Builder(this);
                    builder.SetTitle(Resource.String.app_name);
                    builder.SetMessage(Resource.String.need_to_copy_to_local);
                    builder.SetPositiveButton(Resource.String.yes, (ev, ct) =>
                    {
                        try
                        {
                            Stream stream = ContentResolver.OpenInputStream(uri);
                            var data      = AndroidPlatformUtils.ReadFully(stream);
                            stream.Close();
                            var notify = Path.Combine(PlatformUtils.Instance.GetConfigBasePath(), "notify");
                            PlatformUtils.Instance.EnsureDirectory(notify);
                            streamerData.NotifySoundPath = Path.Combine(notify, streamerData.Id);
                            PlatformUtils.Instance.WriteAllBytes(streamerData.NotifySoundPath, data);
                        }
                        catch
                        {
                            streamerData.NotifySoundPath = null;
                        }
                    });
                    builder.SetNegativeButton(Resource.String.no, (ev, ct) =>
                    {
                    });
                    builder.Show();
                    return;
                }
                // MediaProvider
                else if (isMediaDocument(uri))
                {
                    String docId = DocumentsContract.GetDocumentId(uri);

                    char[]   chars = { ':' };
                    String[] split = docId.Split(chars);

                    String type = split[0];

                    Android.Net.Uri contentUri = null;
                    if ("image".Equals(type))
                    {
                        contentUri = MediaStore.Images.Media.ExternalContentUri;
                    }
                    else if ("video".Equals(type))
                    {
                        contentUri = MediaStore.Video.Media.ExternalContentUri;
                    }
                    else if ("audio".Equals(type))
                    {
                        contentUri = MediaStore.Audio.Media.ExternalContentUri;
                    }

                    String   selection     = "_id=?";
                    String[] selectionArgs = new String[]
                    {
                        split[1]
                    };

                    streamerData.NotifySoundPath = getDataColumn(this, contentUri, selection, selectionArgs);
                    return;
                }
            }
            // MediaStore (and general)
            else if ("content".Equals(uri.Scheme, StringComparison.OrdinalIgnoreCase))
            {
                // Return the remote address
                if (isGooglePhotosUri(uri))
                {
                    streamerData.NotifySoundPath = uri.LastPathSegment;
                    return;
                }
                streamerData.NotifySoundPath = getDataColumn(this, uri, null, null);
                return;
            }
            // File
            else if ("file".Equals(uri.Scheme, StringComparison.OrdinalIgnoreCase))
            {
                streamerData.NotifySoundPath = uri.Path;
                return;
            }
        }