how to use ACTION_PACKAGE_FIRST_LAUNCH intent-filter to start application?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 18:13:11

问题


I am trying to use the intent-filter ACTION_PACKAGE_FIRST_LAUNCH to make the application do some tasks when it first launched, however it not being captured by the broadcast receiver my Manifest

  <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 my broadcast receiver implementation

  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) {


    }

How can i make it start when the app first launched?


回答1:


Sorry those intents except for boot_completed are only sent to the play store. But it is relatively simple to do what you need otherwise. Instead use SharedPreferences, like example:

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();
}


来源:https://stackoverflow.com/questions/17510061/how-to-use-action-package-first-launch-intent-filter-to-start-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!