Frage

I'm using this library https://github.com/commonsguy/cwac-updater to provide feature of auto update for an app.

I read the demoUpdater it uses a deprecated API for Notification, so I used the following code:

ConfirmationStrategy buildPreDownloadConfirmationStrategy(Context mContext) {

        long[] vibrate = { 0, 100, 200, 300 };
        NotificationManager mNotificationManager= (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mContext)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Update Available")
        .setContentText("Click to download the update!")
        .setVibrate(vibrate)
        .setAutoCancel(true)
        .setLights(Color.BLUE, 500, 500);
        mNotificationManager.notify(1, mBuilder.build());
        return null; 

        //return(new NotificationConfirmationStrategy());
    }

but can't get it working.

War es hilfreich?

Lösung

I got it working, If anyone finds trouble then use below code

ConfirmationStrategy buildPreDownloadConfirmationStrategy(Context mContext) {

        long[] vibrate = { 0, 100, 200, 300 };
        NotificationManager mNotificationManager= (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mContext)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Update Available")
        .setContentText("Click to download the update!")
        .setVibrate(vibrate)
        .setAutoCancel(true)
        .setLights(Color.BLUE, 500, 500);
        Notification notification = mBuilder.build();
        mNotificationManager.notify(1, notification);

        return(new NotificationConfirmationStrategy(notification));
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top