Reputation: 327
I trying to detect my application run at first time. I used Broadcast Receiver to do this. It works fine with ACTION_PACKAGE_REPLACED. But it doesn't work when I use ACTION_PACKAGE_FIRST_LAUNCH intent. I'm using Android 4.3
This is my Activity
public class MainActivity extends Activity {
BroadcastReceiver broadcastReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
broadcastReceiver = new TestBroadcast();
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(broadcastReceiver);
}
@Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH);
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
intentFilter.addDataScheme("package");
registerReceiver(broadcastReceiver, intentFilter);
}
}
This is my AndroidManifest.xml
<receiver android:name="com.example.TestBroadcast" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
And TestBroadcast class
public class TestBroadcast extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_PACKAGE_FIRST_LAUNCH)) {
Toast.makeText(context, "Application installed",
Toast.LENGTH_SHORT).show();
}
}
}
Upvotes: 2
Views: 2215
Reputation: 43
Applications would receive these intents. These intents are broadcasted only to Play Store.
Upvotes: 1