我正在尝试使用 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/