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.
4. Create a new VIEW two.xml / TwoActivity.java.
5. Add a 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.
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);
}
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);
}
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.
Hi there,
ReplyDeleteI 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
Dude Why You Not Add To Create Own I mean Create Notiffication and Edit Text And Info And Add Progress Ba4
ReplyDeleteHow can I make the project work on the main screen of the phone like app of the battery
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHow to acces data from any kind of notification.means want activity in response on notification.
ReplyDeleteThe 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);
DeleteThanks
DeleteSir,i need to access normal text message content trough sketchware app,is it possible.
Delete?????????
DeleteThis comment has been removed by the author.
DeleteWhat do you mean??
DeleteA app which is to be read a text message and retrive the part of text or whole,reacting upon the content of message.
DeleteSanjeev, help
DeleteIs it possible to insert a variable string to change the screen? I know it's wrong, but it would be something like this:
Intent notificationIntent = new Intent(getApplicationContext(),(_Screen)Activity.class);
Hi
DeleteHello please tell me how to implement notification for new message in chat ?
ReplyDeleteAny idea how?
DeleteAny idea?
DeleteJust goto OnCHildAdded event and add the above code.
DeleteThen goto OnCustomViewBind of list view.
Then set edittext1 as the message or username as per your requirements
Thank you!
ReplyDeleteCan i creat a notification from web server?
ReplyDeleteGood. Thanks for the code
ReplyDeleteI think hes means can you create an Android widget in sketchware i myself am interested in doing so
ReplyDeleteit's simple:
Deletefor textview "TextView androidText = new TextView(this);"
for edittext "EditText androidEdit = new EditText(getActivity());"
for linear "LinearLayout androidLayout = new LinearLayout(this);"
...
How to make notification permanent?
ReplyDeleteSpam the intent of the phone's CPU by running the code every millisecond. Try that
Deletetanks 👏☺
ReplyDeletehow to integrate the keypad into firebase notification so that client get the message?
ReplyDeleteif the tutorial you share is only for applications that we install ourselves not for clients
This comment has been removed by the author.
ReplyDeleteHow to the send. Push notifications to user .. like one signal push notifications
ReplyDeleteError: Depreciated
ReplyDeleteSame way
DeleteFailed to post on channel null
ReplyDeleteHow to submit app IN sketchware competition
ReplyDeleteHow to get premium sketchware for free
ReplyDeleteNow notification deprecated .
ReplyDeleteHow could I solve it
You need to specify channel in builder . Does not generate run errors .
Deletehai.. i love your blog so much!!!
ReplyDeleteHow do I make a webview riderect to the Play Store application when I will download an application from Google?
Thank you for the help..
Hi. Why notifications do not work to all devices? This procedure give good results only to some phones.
ReplyDeletehow to integrate the firebase notification so that client get the message?
ReplyDeletebcz the tutorial you shared is only for applications that we install ourselves not for clients
create push notifications sketchware
ReplyDeleteBut it's not working on Android 8 and higher...
ReplyDeleteHow to do it in new Android versions?
P.s. sorry for long mail.
Bro chat notification?
ReplyDeleteThis Code for implementing Notifications don't work with Android 8. There is a New codes?
ReplyDeleteI 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.
ReplyDeleteThoughts?
Can you guys please help me about how to show listview contents in notifications when a listview item is clicked.
ReplyDeleteHow to make notifications for newly added data in listview on Firebase
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi ,
ReplyDeleteI 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)
How set Snal Icon from file picker and size of the icon
ReplyDeleteBagaimana cara membuat notifikasi untuk orang yang menjawab pertanyaan kalau dia memang orangnya yg jawab dengan benar
ReplyDeleteHow can I set image picked up from file picker as icon for image
ReplyDeleteI followed your instructions but I got 5 errors android.support.v4.app.NotificationCompat cannot resolved to a type
ReplyDeleteDid you solve it?
Deletei have the same erros(3) "android.support.v4.app.NotificationCompat cannot resolved to a type. someone can help. i have android10
DeleteImport news that android.support.v4 has been changed to androidx.core by Google . but still after changing it I'm getting error (5)
DeleteI am created a project, and I want to run my application in background and to show notification on specific time.
ReplyDeleteIf application is not open
You need to run service
DeleteThis comment has been removed by the author.
ReplyDeleteI have an activity called newActivity and it contains a drawer and a shared preference called time, and i have a custom view called drawer and it contains a switch now when you click the switch in the drawer i set the shared preference data key time to "ok" now what i want to do is dat in newActivity On create if shared preference time = "ok" i set the switch checked =true else i set checked to false but the problem is the switch object doesn't show when I'm in the on Create please help me how to do it, i want to save the state of the switch when you exit the app
ReplyDeleteUse add source directly block. The id of switch will be _drawer_switch1 or something like that.
Delete_drawer_switch1.setChecked(true);
Is their any way to send notification directly from OneSignal Dashboard, as we send using Firebase
ReplyDelete