Mus*_*lla 5 android intentfilter broadcastreceiver android-manifest
我正在尝试使用intent-filter ACTION_PACKAGE_FIRST_LAUNCH使应用程序在首次启动时执行某些任务,但是它没有被广播接收器捕获我的清单
<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>
Run Code Online (Sandbox Code Playgroud)
这是我的广播接收器实现
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) {
}
Run Code Online (Sandbox Code Playgroud)
如何在应用程序首次启动时启动它?
抱歉,除 boot_completed 之外的其他意图仅发送到 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();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5116 次 |
最近记录: |