【问题标题】:Android - How to start an application on the /sdcard after bootAndroid - 如何在启动后在 /sdcard 上启动应用程序
【发布时间】:2011-08-10 03:55:42
【问题描述】:

如果它在/sdcard上,有没有办法在启动后自动启动android应用程序?

好的,可能是BroadcastReceiver。但是哪个动作是正确的呢?

ACTION_BOOT_COMPLETED - does not work if it is on the /sdcard (documented)
ACTION_MEDIA_MOUNTED - does not work if it is on the /sdcard (which is undocumented)
ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - does not work, I do not know why
ACTION_USER_PRESENT - does not work if the BroadcastReceiver is registered in AndroidManifest (which is undocumented, but documentation bug has been reported)

谢谢
一月

【问题讨论】:

  • 你解决过这个问题吗?我现在也遇到了类似的问题。
  • 您的问题帮助我找到了答案,谢谢。 :D
  • 如果你觉得有帮助,你应该接受答案。
  • 恐怕这个问题唯一正确的答案是:不,没有办法。
  • 这个问题stackoverflow.com/questions/8248617/… 正确回答了这个问题,即为BOOT_COMPLETEDMEDIA_MOUNTED 创建一个接收器

标签: android broadcastreceiver sd-card boot


【解决方案1】:

尝试使用<receiver android:name=".BootCompleteReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver>

还有这个&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;

也许 QUICKBOOT_POWERON 可以帮助你

【讨论】:

    【解决方案2】:

    请在清单文件中提及。

    </uses-permission>    
    <receiver android:name=".BootReceiver"
        android:enabled="true"
        android:exported="true"
        android:label="BootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
        </intent-filter>
    </receiver>
    

    提供权限“android.permission.RECEIVE_BOOT_COMPLETED”作为清单的孩子。

    还有一件事你的应用不能安装在 sdcard 中。

    【讨论】:

    • 这没有回答问题,因为该问题专门询问了当应用程序安装在 SD 卡上时如何在启动时收到通知。
    • 我不确定,但在我看来这是不可能的。
    • 我同意,所以正确的答案是不可能。
    【解决方案3】:

    根据 Google 的说法,您不应将任何想要在启动时运行的应用程序放在外部驱动器上。

    “系统在将外部存储挂载到设备之前发送ACTION_BOOT_COMPLETED广播。如果您的应用程序安装在外部存储上,它永远无法接收到此广播。”

    http://developer.android.com/guide/topics/data/install-location.html#ShouldNot

    【讨论】:

      【解决方案4】:

      我通常以两种方式为广播接收器注册每个意图过滤器(Android 清单以及在扩展应用程序的类中动态地)

      在 AndroidManifest.xml 中为:

          <receiver
                  android:name=".broadcastReciever"
                  android:enabled="true"
                  android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
                  <intent-filter>
                      <action android:name="android.intent.action.BOOT_COMPLETED" />
                      <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
                  </intent-filter>
              </receiver>
      

      在扩展应用程序的类中:

      registerReceiver(new broadcastReciever(), new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE));
      

      不要忘记添加RECEIVE_BOOT_COMPLETED 权限并在Android Manifest 中注册扩展Application 的类。

      应该这样做;随时寻求更多帮助/澄清。

      【讨论】:

        猜你喜欢
        • 2012-05-12
        • 2019-06-15
        • 2017-03-07
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 2017-09-02
        • 2020-02-10
        • 2013-10-22
        相关资源
        最近更新 更多