用户从Play商店安装后,从应用程序发送欢迎通知?

时间:2016-08-31 19:34:54

标签: android push-notification notifications

我想向Play商店安装的应用发送欢迎消息通知。

示例:

  

Thanx用于安装此应用并与您的朋友分享,如果您想要更高的费率 my android app

是否可以这样做?

2 个答案:

答案 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次访问时触发通知。当用户点击通知时,它会将他带到商店直接到您可以评分的应用程序