Intent_Filter Action 在 AndroidManifest 中不起作用

发布于 2024-09-27 02:19:33 字数 1905 浏览 0 评论 0原文

我有一个活动,它还必须收听来自自制服务的特定广播。 我注意到,当我将其添加为 Androidmanifest 文件中的操作时,应用程序在调试时实际上不会启动。 该活动也是我的主要活动:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

但是当我向其中添加自己的额外操作时,它根本不会接收广播,并且在调试时不会自行启动???

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
   <action android:name="development.android.service.musicServiceUpdate">
</intent-filter>

知道这里出了什么问题或者为什么我的活动不会收到广播吗? 是否可以为 .MAIN 操作指定两个操作?

/编辑:

尝试以下操作:

<activity android:name=".nowPlayingGUI"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait"
                    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                    android:launchMode="singleTask">    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".nowPlayingGUI">
            <intent-filter>
                <action android:name="development.android.service.musicServiceUpdate"></action>
            </intent-filter>
        </receiver>

这不起作用,并且会抛出:

10-14 11:57:04.412: ERROR/AndroidRuntime(11947): java.lang.RuntimeException: 无法实例化接收器development.android.myPlayer.nowPlayingGUI :java.lang.ClassCastException:development.android.myplayer.nowPlayingGUI

10-14 11:57:04.412:错误/AndroidRuntime(11947):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)

I have an Activity which also has t olisten to a specific broadcast from a self-made service.
I have noticed though that when I add that as an action to my Androidmanifest file the app won't actually start whilst debugging.
The Activity is also my MAIN activity :

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

But when I add my own extra action to it it simply wont pick up the broadcast and it won't start up out of itself whilst debugging ????

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
   <action android:name="development.android.service.musicServiceUpdate">
</intent-filter>

Any idea whats wrong here or why my activity wont be catching the broadcast ?
Is it possible to have two action's specified to a .MAIN action ?

/edit :

Tried the following :

<activity android:name=".nowPlayingGUI"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait"
                    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                    android:launchMode="singleTask">    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".nowPlayingGUI">
            <intent-filter>
                <action android:name="development.android.service.musicServiceUpdate"></action>
            </intent-filter>
        </receiver>

That won't work and will throw a :

10-14 11:57:04.412: ERROR/AndroidRuntime(11947): java.lang.RuntimeException: Unable to instantiate receiver development.android.myPlayer.nowPlayingGUI: java.lang.ClassCastException: development.android.myplayer.nowPlayingGUI

10-14 11:57:04.412: ERROR/AndroidRuntime(11947): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

极致的悲 2024-10-04 02:19:33

我刚刚遇到了同样的问题。尝试将该意图过滤器中的操作顺序更改为:

<intent-filter>
   <action android:name="development.android.service.musicServiceUpdate">
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

I just hit this same problem. Try changing the order of the actions in that intent-filter to this:

<intent-filter>
   <action android:name="development.android.service.musicServiceUpdate">
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
猫烠⑼条掵仅有一顆心 2024-10-04 02:19:33

每个意图过滤器只能有一个操作(但可以有多个类别)。相反,添加一个额外的意图过滤器。

You can only have one action per intent filter (but you can have multiple categories). Add an additional intent filter instead.

倒数 2024-10-04 02:19:33

您是否在 androidmanifest.xml 中添加了标签

假设您有一个活动和一个广播接收器,我认为您的清单 xml 将在您的应用程序标签中包含与此类似的内容:

    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name =".myreceiver">
           <intent-filter>
              <action android:name=development.android.service.musicServiceUpdate />
         </intent-filter>
    </receiver>

Have you added the tag in your androidmanifest.xml

Assuming you have an activity and a broadcast receiver, I think your manifest xml would contain something similar to this inside your app tag:

    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name =".myreceiver">
           <intent-filter>
              <action android:name=development.android.service.musicServiceUpdate />
         </intent-filter>
    </receiver>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文