Senin, 16 Oktober 2017

Code for implementing Notifications in Sketchware

In the new versions​ of Sketchware we can insert java code directly, which makes several new actions possible in Sketchware including notifications.

If you know the code, it is very easy to implement notifications in your android project. The code to be used is provided below.

In your Sketchware project, add an image (say imageiconxyz) which will be displayed as notification image.

Then choose the event on which you want to show notification (on button click, on image click, on Activity Create, etc.).

Suppose you want to display notification when a button is clicked. Then onButtonClick event use block add source directly and write the following code:

Notification.Builder mBuilder = new Notification.Builder(MainActivity.this);
mBuilder.setSmallIcon(R.drawable.imageiconxyz);
mBuilder.setContentTitle("title");
mBuilder.setContentText("text");
mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

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

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

mBuilder.setContentIntent(pendingIntent).setAutoCancel(true);
notificationManager.notify(1, mBuilder.build());

The first underlined text 'MainActivity' is the name of the page on which you are using the code. Change it as per the name of the page or activity.

The second underlined text 'imageiconxyz' is name of the image which will act as notification icon. Change it as per the name of the image you have added.

The third underlined text 'title' is the title of the notification. Change it as per your requirement.

The fourth underlined text 'text' is the text shown as notification. Change it as per your requirement.

The last underlined text 'MainActivity.class' is the name of the activity or page which opens when the notification is clicked. Change it if you wish to open any other screen.

You can also set Custom View 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
mBuilder.setContentTitle("title");
mBuilder.setContentText("text");

with
mBuilder.setContent(contentView);

This will display the contents of Custom View as notification.

To learn more watch the video below:

Share:

0 komentar:

Posting Komentar

Alam terbuka mengasyikkan di Destinasi impian

Jasa Pembuatan Website Archives - Legenda Web

loading...

Archive

Cari Blog Ini

Diberdayakan oleh Blogger.

Mengenai Saya

Foto saya
Saya memiliki Jasa Pembuatan Website Terpercaya
www.legendaweb.com

Pernah mengerjakan seo untuk Agen Travel door to door ecopremieretransindo.com dan Agen Travel Jakarta Jogja jakjogtrans.com

Juga memegang SEO Biro jasa paspor

Selain Itu, kerjasama dengan Sewa Mobil Bali Mai Bali Trans dan Industri pariwisata trip Bali dari beautrip.id

Labels

Admob ads in Sketchware Admob Ads in Sketchware App admob ads using AIDE Admob banner ads using AIDE Admob interstitial Ads Android app Android change status bar color animation in Sketchware background music Change color of checkbox in Sketchware change color of Seekbar change color of Switch button change status bar color code for moving image with finger in android code Injection create and share text file in Sketchware create text file in Sketchware Custom listview in android Custom ListView in Sketchware CustomView in Sketchware Dictionary Android App Dictionary Android project Dictionary App Dictionary App in Sketchware drag image enable download from Sketchware enable download in webview enable download without code Injection Enable image upload enable upload from webview enable upload from webview in android enable upload in Sketchware enable upload in webview​ using AIDE enable upload using AIDE gif image in Android App gif image in webview how to use ListView in Sketchware how to use Spinner image zoom Integrate Admob Ads in Sketchware Intent large paragraphs in Sketchware larger texts in Edittext. limit input text length load image in webview make image fit screen make scrollbar invisible media player move image with finger notification icon in Android notification in Android Notifications in Sketchware open other apps retrieve APK file retrieve source code share button share button in Android App share button in Sketchware App Share text file Sketchware sound on off sound play pause soundpool Soundpool for Multiple sounds Sounds in Android App stopwatch Android App Stopwatch App string list timer use of list