如何从代码中打开Android 5中的音乐应用程序(how to open a music app in android 5 from code)
如何在Android 5中打开音乐应用程序从默认情况下开始播放第一首歌的代码而不给出任何特定查询,我厌倦了“android.intent.category.APP_MUSIC”,但它显示错误,因为没有默认的应用程序来处理这个意图,请帮忙!
how to open a music app in android 5 from code which starts playing the first song by default without giving any specific query, i tired "android.intent.category.APP_MUSIC" , but it shows error as to there is no default application to handle this intent, please help !
原文:https://stackoverflow.com/questions/35251505
最满意答案
我不想在这里添加一个答案,因为您已经解决了您的问题,我所说的不会为您遇到的问题提供任何答案,但它不适合作为评论,因为我提供了一些代码。 所以我不得不在这里发布它作为答案。
你可能已经知道了(并没有这样写,所以你的问题中的代码更简单),但我只是想说,分配非托管内存时应该在每个地方使用的最佳实践是封装代码在try / finally块中,以确保内存总是被释放 ,即使抛出异常:
private static void Test() { IntPtr ptrStruct = IntPtr.Zero; try { Marshal.AllocHGlobal(0x100); // Some code here // At some point, an exception is thrown throw new IndexOutOfRangeException(); } finally { // Even if the exception is thrown and catch // from the code that calls the Test() method, // the memory will be freed. if (ptrStruct != IntPtr.Zero) { Marshal.FreeHGlobal(ptrStruct); } } } try { Test(); } catch (IndexOutOfRangeException) { // Catches the exception, so the program won't crash // but it'll exit the Test() method, so the try/finally // ensures it won't leave without freeing the memory Debugger.Break(); }
I didn't want to add an answer here as you already have solved your problem and what I'll say won't provide any answer to the problem you had, but it wouldn't fit well as a comment as I provide some code. So I'm obliged to post it here as an answer.
You may already know it (and didn't wrote it that way so the code in your question is simpler), but I just wanted to say that a best practice that should be used everywhere when unmanaged memory is allocated, is to encapsulate the code in a try/finally block to ensure the memory is always freed, even if an exception is thrown:
private static void Test() { IntPtr ptrStruct = IntPtr.Zero; try { Marshal.AllocHGlobal(0x100); // Some code here // At some point, an exception is thrown throw new IndexOutOfRangeException(); } finally { // Even if the exception is thrown and catch // from the code that calls the Test() method, // the memory will be freed. if (ptrStruct != IntPtr.Zero) { Marshal.FreeHGlobal(ptrStruct); } } } try { Test(); } catch (IndexOutOfRangeException) { // Catches the exception, so the program won't crash // but it'll exit the Test() method, so the try/finally // ensures it won't leave without freeing the memory Debugger.Break(); }
相关问答
更多-
在XP和Windows 7 PC中将.NET 4.0程序集安装到GAC(Installing .NET 4.0 assemblies to GAC in XP and Windows 7 PCs)[2023-09-01]
通常, Win7 64位和32位Dll的GAC文件夹路径是不同的。 而在XP它位于相同的文件夹下。 但是当通过MSI向GAC添加组件时,我们真的不需要担心内置版本。 基于内置版本,MSI将在64或32位文件夹下注册它们。 Normally GAC folder paths are different for 64 and 32 bit Dlls in Win7. Whereas in XP it resides under same folder. But when adding assembly to G ... -
.NET 4.0是否与Windows XP SP2兼容?(Is .NET 4.0 Compatible with Windows XP SP2 or below? [closed])[2022-05-26]
.NET 3.5将提供与XP SP2的兼容性。 如果您希望兼容任何级别的XP,您需要一直回到.NET 2.0。 .NET 3.5要求可以在这里找到: http : //msdn.microsoft.com/en-us/library/cc160717(VS.90).aspx .NET 3.0要求可以在这里找到: http : //msdn.microsoft.com/en-us/library/aa480198.aspx .NET 3.5 will give you compatibility with X ... -
我不想在这里添加一个答案,因为您已经解决了您的问题,我所说的不会为您遇到的问题提供任何答案,但它不适合作为评论,因为我提供了一些代码。 所以我不得不在这里发布它作为答案。 你可能已经知道了(并没有这样写,所以你的问题中的代码更简单),但我只是想说,分配非托管内存时应该在每个地方使用的最佳实践是封装代码在try / finally块中,以确保内存总是被释放 ,即使抛出异常: private static void Test() { IntPtr ptrStruct = IntPtr.Zero; ...
-
使用.NET 4.0或.NET 3.5?(Use .NET 4.0 or .NET 3.5?)[2022-03-06]
根据这篇MSDN文章,您不需要在Windows 8上安装3.5,因为它是向后兼容的: .NET Framework 4向后兼容使用.NET Framework 1.1,2.0,3.0和3.5构建的应用程序。 换句话说,使用以前版本的.NET Framework构建的应用程序和组件将在.NET Framework 4上运行。 此外,这个问题可能很有趣: https ://serverfault.com/questions/121563/are-net-versions-backwards-compatible ... -
此问题与Windows XP上的httpcfg要求有关。 通过使用现有的localhost:8732 / Design_Time_Addresses来自行托管WCF解决了这个问题。 它需要为urlacl添加选择端口,权限类似于8732。 This issue is related to httpcfg requirement on Windows XP. It was resolved by using existing localhost:8732/Design_Time_Addresses to sel ...
-
这是问题所在: 我们一直在使用名为VirtualBox的VM,其上安装了Windows XP。 我们尝试安装Visual Studio 2010并从那里调试应用程序但是没有成功。 经过两天的讨论,为什么这不起作用我们尝试使用VMWare工作站,它工作得很好!! VirtualBox软件必定存在某些问题。 谢谢你们的建议! Here's what the problem was : We have been using a VM named VirtualBox which had Windows XP in ...
-
是的我会安装.NET Framework 3.5并重试,如果它不起作用我将安装3.0( Microsoft .NET Framework 3.0 Redistributable Package )。 .NET 3.5 SP1和.NET 4都存在于我们部署应用程序的机器中。 编辑: 还要检查以下问题: 我应该附带什么.NET Framework版本; 2,3,3.5? 如果安装了3.5,是否需要.net framework 2.0? yes I would install the .NET Framework ...
-
支持的平台更新,无需提供某些操作系统升级。 现在可以通过帮助管理器下载文档 。 The supported platforms are newer, there is no need to ship some OS upgrades. Documentation is now an optional download via help manager.
-
我的建议是不需要卸载.Net4。 .NET4将支持所有较低版本。 关于卸载,请使用.NET Framework清理工具 。 从这里获取它。 http://blogs.msdn.com/b/astebner/archive/2008/08/01/8803442.aspx http://blogs.msdn.com/b/astebner/archive/2010/05/13/10012778.aspx My suggestion is no need to uninstall the .Net4. .NET4 ...
-
Crystal Reports从.NET 4.0降级到.NET 3.5(Crystal Reports downgrade from .NET 4.0 to .NET 3.5)[2023-08-19]
检查这个问题,它可能对您有所帮助: c#更改框架错误 “您可以尝试通过右键单击.resx文件并从上下文菜单中选择”运行自定义工具“来重新生成文件。 Check this question, it might help you: c# change framework error "You can try regenerating the file by right-clicking the .resx file and choosing 'Run Custom Tool' from the context ...