Android Studio development learning notes - 4

Recently, I haven't updated my blog for a long time. I've been busy with the studio project recently. By the way, I went out for a tour on national day to relax myself. It turns out that I was wrong. It's a distraction. It's a distraction. It's a person everywhere. I'll go out to play in the future. It's definitely not on holidays.

Recently, if you have nothing to do, you can read and code and finish the homework assigned by the teacher. I uploaded some good examples to my GitHub Here are some Android examples I typed

The code will be updated all the time. Welcome to fork.

When I clicked the notification notification component, I found that I could run on the real machine, but I couldn't pop up the notification on the simulator. Later, I found that my mobile phone was Android 6.0, but the simulator was Android 8.0. Android needs to add a notification channel for notifications after 8.0 to see the code

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                int NOTIFYID_1 = 1;
                String id = "1";
                String name = "channel_1";
                NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
                NotificationManager notificationManager;
                notificationManager.createNotificationChannel(mChannel);

                Intent intent = new Intent(this, TestActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
                Notification.Builder mBuilder = new Notification.Builder(this);
                mBuilder.setContentTitle("A notice title")
                    .setContentText("This is the content of a notice")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                    .setAutoCancel(true)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setContentIntent(pendingIntent);
                    .setChannelId(id);
                Notification notification = mBuilder.build();
                notificationManager.notify(NOTIFYID_1, notification);
}

 

Keywords: Android simulator github Mobile

Added by Smeep on Sun, 15 Dec 2019 23:26:03 +0200