答案 0 :(得分:0)
你可能会做这样的事情来了解应用安装事件
在清单文件中:
<receiver android:name=".YourReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
在java代码中
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");
registerReceiver(br, intentFilter);
答案 1 :(得分:0)
private void checkVisit() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
int numberVisits = sharedPreferences.getInt(NUMBER_VISITS, 0);
if(numberVisits >= 10){
boolean notificationSent = sharedPreferences.getBoolean(NOTIFICATION_SHOWN, false);
if(!notificationSent) {
sendNotification();
editor.putBoolean(NOTIFICATION_SHOWN, true);
}
} else{
editor.putInt(NUMBER_VISITS, ++numberVisits);
}
editor.apply();
}
private void sendNotification() {
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle("Thanks for downloading !")
.setContentText("If you liked the app, please rate us")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(icon)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("If you liked the app, please rate us"))
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "YOUR PACKAGE NAME GOES HERE"))
, 0))
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
在MainActivity中调用checkVisit onCreate,这将在他第10次访问时触发通知。当用户点击通知时,它会将他带到商店直接到您可以评分的应用程序