Code for implementing Notifications in Sketchware

This tutorial shows a Sketchware android project example in which a Notification is displayed when a Button is clicked and when the Notification is clicked, it opens a new Activity.

1. Create a new project in Sketchware. In VIEW area add an EditText edittext1, and a Button button1.

2. Using Image Manager add an images mail_white. This will be used as the Notification icon.

3. In Library manager switch on AppCompat and Design.

4. Create a new VIEW two.xml / TwoActivity.java.

5. Add a More Block: createChannel.

6. In More Block createChannel, use add source directly block and put following code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel name 1";
String description = "Notification channel";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("id 1", name, importance);
channel.setDescription(description);

NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);

}

7. In onCreate event, use the More Block createChannel.


8. Suppose you want to display content in edittext1 as notification when button1 is clicked. Then in button1 onClick event use an add source directly block and write the following code:

Intent intent = new Intent(MainActivity.this, TwoActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(MainActivity.this, "id 1")
.setSmallIcon(R.drawable.mail_white)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentTitle("My notification")
.setContentText("The text in EditText is " + edittext1.getText().toString())
.setPriority(android.support.v4.app.NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);

android.support.v4.app.NotificationManagerCompat notificationManager = android.support.v4.app.NotificationManagerCompat.from(MainActivity.this);
notificationManager.notify(1, builder.build());

'MainActivity.this' has to be changed to the Activity in which the code is used.

'TwoActivity.class' has to be changed to the Activity to be opened when notification is clicked.

Change contentTitle, contentText and SmallIcon as per your requirement.

9. You can also set a CustomView in Sketchware as notification by making little modifications to the code above. Suppose name of your Custom View is 'cview.xml'. Then add the following code just before the code provided above, to display it as notification:

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.cview);

Now in the code provided earlier, replace
.setContentTitle("My notification")
.setContentText("The text in EditText is " + edittext1.getText().toString())

with
.setContent(contentView)

This will display the contents of Custom View as notification.

10. Save and run the project. When button1 is clicked, it displays a notification showing contents of edittext1, and when the Notification is clicked, it opens TwoActivity.

Comments

  1. Hi there,
    I watch your videos on the youtube and i learn many tricks about sketchware, but i have a question: i need to put a web page in a string to edit it and extract some data. There many "how to" about it in the internet, but only works in the android studio. Can you help me? How to put a entire web page in a string in sketchware?

    Thank you,

    Flávio (from Brazil)
    my email: flavio23paula@gmail.com

    ReplyDelete
  2. Dude Why You Not Add To Create Own I mean Create Notiffication and Edit Text And Info And Add Progress Ba4

    ReplyDelete
  3. How can I make the project work on the main screen of the phone like app of the battery

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. How to acces data from any kind of notification.means want activity in response on notification.

    ReplyDelete
    Replies
    1. The intent part in code above let's it open MainActivity. You can change that to open any other Activity. Change it in this line: Intent notificationIntent = new Intent(getApplicationContext(),MainActivity.class);

      Delete
    2. Sir,i need to access normal text message content trough sketchware app,is it possible.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. A app which is to be read a text message and retrive the part of text or whole,reacting upon the content of message.

      Delete
  6. Hello please tell me how to implement notification for new message in chat ?

    ReplyDelete
  7. I think hes means can you create an Android widget in sketchware i myself am interested in doing so

    ReplyDelete
    Replies
    1. it's simple:
      for textview "TextView androidText = new TextView(this);"
      for edittext "EditText androidEdit = new EditText(getActivity());"
      for linear "LinearLayout androidLayout = new LinearLayout(this);"
      ...

      Delete
  8. How to make notification permanent?

    ReplyDelete
    Replies
    1. Spam the intent of the phone's CPU by running the code every millisecond. Try that

      Delete
  9. how to integrate the keypad into firebase notification so that client get the message?
    if the tutorial you share is only for applications that we install ourselves not for clients

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. How to the send. Push notifications to user .. like one signal push notifications

    ReplyDelete
  12. Failed to post on channel null

    ReplyDelete
  13. How to submit app IN sketchware competition

    ReplyDelete
  14. How to get premium sketchware for free

    ReplyDelete
  15. Now notification deprecated .
    How could I solve it

    ReplyDelete
    Replies
    1. You need to specify channel in builder . Does not generate run errors .

      Delete
  16. hai.. i love your blog so much!!!

    How do I make a webview riderect to the Play Store application when I will download an application from Google?

    Thank you for the help..

    ReplyDelete
  17. Hi. Why notifications do not work to all devices? This procedure give good results only to some phones.

    ReplyDelete
  18. how to integrate the firebase notification so that client get the message?
    bcz the tutorial you shared is only for applications that we install ourselves not for clients

    ReplyDelete
  19. create push notifications sketchware

    ReplyDelete
  20. But it's not working on Android 8 and higher...
    How to do it in new Android versions?

    P.s. sorry for long mail.

    ReplyDelete
  21. This Code for implementing Notifications don't work with Android 8. There is a New codes?

    ReplyDelete
  22. I found that this works terrific on my device, however, it does not push the notification to other devices. For example, say a chat app, when I send a message, I get notified that I sent it. None of the other 6 devices recieve notification, just the message.
    Thoughts?

    ReplyDelete
  23. Can you guys please help me about how to show listview contents in notifications when a listview item is clicked.

    ReplyDelete
  24. How to make notifications for newly added data in listview on Firebase

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Hi ,
    I want to create a to-do list app.
    In that even if the app activity gets destroyed,i still want to give user a notification about completing task as a reminder. Is it possible through sketchware.

    (Eg. Like any alarm app , even if we close the app from RAM it still rings at certain time)

    ReplyDelete
  27. How set Snal Icon from file picker and size of the icon

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity