How to make Android X Supported Notifications in sketchware?

Hey guys today in this blog I will teach you how can you make Android X Supported Notifications in Sketchware using more blocks.

Follow the steps:

1. Start the Sketchware app.
2. Then click on "+" fab to add your app.
3. Now write the name of your app.
4. And click on "create app" then your app will be ready to be created.
5. Drag "Button" to the design field.


6. Then move to "Event" and click on "more block".
7. Then click to add more blocks.
8. Then write the name of more block as "notifications".
9. Now add a text label in it with the name "addTitle".
10. Then add a "String" variable and name it "Title".
11. Then again add a text label in it with the name "addContent".
12. And then again add a "String" variable with the name "Content".


13. Then click on add More Block.
14. Click on the more block that you have created now.
15. And drag a "add source directly" block from "operator"

16. Then paste the following code:

final Context context = getApplicationContext();


NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(this, MainActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
androidx.core.app.NotificationCompat.Builder builder; 
int notificationId = 1;
    String channelId = "channel-01";
    String channelName = "Channel Name";
    int importance = NotificationManager.IMPORTANCE_HIGH;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel mChannel = new NotificationChannel(
                channelId, channelName, importance);
        notificationManager.createNotificationChannel(mChannel);
    }
 androidx.core.app.NotificationCompat.Builder mBuilder = new androidx.core.app.NotificationCompat.Builder(context, channelId)
            .setSmallIcon(R.drawable.app_icon)
            .setContentTitle(_Title)
            .setContentText(_Content)
            .setAutoCancel(true)
            .setOngoing(false)
            .setContentIntent(pendingIntent);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
    );
    mBuilder.setContentIntent(resultPendingIntent);

    notificationManager.notify(notificationId, mBuilder.build());


[ You can also download more block from sketchware as we have also shared it in sketchware]

17. Then in the code, you need to mention the icon name as shown in the image. ( This icon should be in png format).

18. Then Save and move back to "View".
19. Then move to "View" and click on "Button 1".
20. Then drag the More block and Write the Title and Content in the given space.
21. Then click to run and it will look like this :

For more info you can visit our Youtube video:

Thanks for visiting our blog.


How to make Android X Supported Notifications in sketchware? How to make Android X Supported Notifications in sketchware? Reviewed by Shahbaz Hashmi Ansari on July 13, 2020 Rating: 5

3 comments:

  1. How i can implement bigTextStyle?
    I would like to have several _Content lines in the notification

    ReplyDelete
    Replies
    1. Delete .setContentText(_Content) and replace it with .setStyle(new androidx.core.app.NotificationCompat.BigTextStyle().bigText(_Content))

      Delete

Powered by Blogger.