android - 如何使用 ACTION_PACKAGE_FIRST_LAUNCH intent-filter 启动应用程序?

标签 android broadcastreceiver android-manifest intentfilter

我正在尝试使用 intent-filter ACTION_PACKAGE_FIRST_LAUNCH 让应用程序在首次启动时执行一些任务,但是它没有被广播接收器捕获 我的 list

  <receiver android:name=".reminder.ReminderActionReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
            <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>

这是我的广播接收器实现

  this.context = context;
    String mAction = intent.getAction();
    Log.i("r", mAction);
    if (mAction == Intent.ACTION_PACKAGE_DATA_CLEARED) {

    } else if (mAction == Intent.ACTION_PACKAGE_FIRST_LAUNCH) {


    }

如何让它在应用首次启动时启动?

最佳答案

抱歉,除了 boot_completed 之外,这些 Intent 仅发送到 Play 商店。但是做你需要做的事情相对简单。而是使用 SharedPreferences,例如:

public static final String KEY_PREFS_FIRST_LAUNCH = "first_launch";
// ...
SharedPreferences prefs = SharedPreferences.getDefaultSharedPreferences(this);
if(prefs.getBoolean(KEY_PREFS_FIRST_LAUNCH, true))
{
    //first launch
    prefs.edit().putBoolean(KEY_PREFS_FIRST_LAUNCH,false).commit();
}

关于android - 如何使用 ACTION_PACKAGE_FIRST_LAUNCH intent-filter 启动应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17510061/

相关文章:

android - Chrome 自定义标签页的关闭按钮功能覆盖

java - 安卓 : Implement Broadcast Receiver for ClipboardManager

Android - Intent 以某种方式增加?

android - 我的应用程序在最初启动到设备时加载,但在我退出应用程序并返回后,它甚至不会尝试启动

android - Gradle、Android Studio 和 Butterknife 的编译错误

android - 从后台服务中使用相机

android - BroadCast Receiver 太多实例 OutgoingCallBroadcaster;实例=2;限制=1

android - 在 Nexus 7 大屏幕上缩小 xlarge 应用程序

android - Unity3DGenerateManifest.cs

android - 授予当前用户对/dev/kvm 的访问权限