[Android] Bài 60: Notification là gì và quan trọng thế nào ?

Thảo luận trong 'Android' bắt đầu bởi hieu, 30/3/18.

  1. hieu

    hieu Administrator Thành viên BQT

    Tham gia ngày:
    20/3/18
    Bài viết:
    40
    Đã được thích:
    29
    Điểm thành tích:
    18
    [​IMG]
    nhận gửi thông báo đúng lúc
    thì bài này hiểu sơ sơ về nó trước đã.. qua bài sau xử lý từ php server tao ra 1 body gửi vào máy các client sử dụng app..

    cũng ko có gì nhiều
    new project
    activity_main.xml
    HTML:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Notification"
            android:id="@+id/textView"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:textSize="30dp" />
        .
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BB SINBAD"
            android:id="@+id/textView2"
            android:layout_below="@+id/textView"
            android:layout_centerHorizontal="true"
            android:textSize="35dp"
            android:textColor="#ff16ff01" />
    
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:layout_below="@+id/textView2"
            android:layout_alignLeft="@+id/textView2"
            android:layout_alignStart="@+id/textView2"
            android:layout_marginTop="52dp"
            android:layout_alignRight="@+id/textView2"
            android:layout_alignEnd="@+id/textView2"
            android:hint="Name" />
    
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText2"
            android:hint="Subject"
            android:layout_below="@+id/editText"
            android:layout_alignLeft="@+id/editText"
            android:layout_alignStart="@+id/editText"
            android:layout_alignRight="@+id/editText"
            android:layout_alignEnd="@+id/editText" />
    
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/editText3"
            android:hint="Body"
            android:layout_below="@+id/editText2"
            android:layout_alignLeft="@+id/editText2"
            android:layout_alignStart="@+id/editText2"
            android:layout_alignRight="@+id/editText2"
            android:layout_alignEnd="@+id/editText2" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Notification"
            android:id="@+id/button"
            android:layout_marginTop="77dp"
            android:layout_below="@+id/editText3"
            android:layout_alignRight="@+id/textView"
            android:layout_alignEnd="@+id/textView" />
    
    </RelativeLayout>
    
    MainActivity.java
    HTML:
    package com.example.hieuhuynh.notifcationbai1;
    
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.content.Context;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity {
        EditText ed1,ed2,ed3;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            ed1=(EditText)findViewById(R.id.editText);
            ed2=(EditText)findViewById(R.id.editText2);
            ed3=(EditText)findViewById(R.id.editText3);
            Button b1=(Button)findViewById(R.id.button);
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String tittle=ed1.getText().toString().trim();
                    String subject=ed2.getText().toString().trim();
                    String body=ed3.getText().toString().trim();
    
                    NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                    Notification notify=new Notification.Builder
                            (getApplicationContext()).setContentTitle(tittle).setContentText(body).
                            setContentTitle(subject).setSmallIcon(R.drawable.ic_launcher_background).build();
    
                    notify.flags |= Notification.FLAG_AUTO_CANCEL;
                    notif.notify(0, notify);
                }
            });
        }
    }
    
     
    Chỉnh sửa cuối: 30/3/18
  2. FrankJScott

    FrankJScott Member

    Tham gia ngày:
    20/12/22
    Bài viết:
    245
    Đã được thích:
    0
    Điểm thành tích:
    16
    In response to the lady asking about best entry and exit indicators, 5ers forex, forex vps, kraken futures fees, fully automated algo trading, best automated forex signals, I highly suggest this excellent crypto trading info or demo trading crypto, meta forex, mt4 online, best currency pairs to trade, primexbt bonus, best crypto app for trading, on top of this useful crypto trading blog alongside all forex brokers list, most traded crypto, 3commas tradingview bot, iq option auto trading bot, auto software for share market, automated forex trading signals, and don't forget this new crypto trading forum which is also great. Also, have a look at this updated crypto trading details and don't forget trading auto robot, auto trading brokers, high frequency forex, algo trading with amibroker, high leverage forex brokers, primexbt bonus, and don't forget this top crypto trading tips alongside all no deposit bonus forex, easiest crypto exchange, oanda leverage, algo trading metatrader 5, udemy forex robot, forex ea trader, on top of new crypto trading info which is also worth a look. I also recommend this useful crypto trading advice alongside all best cryptocurrency trading platform, scalper trader, swap cryptocurrency, successful forex traders, most traded currency pairs, best site for buying cryptocurrency, as well as this top crypto trading details and don't forget forex trading tips today, best forex vps, option robot automated software, all about forex trading, cryptocurrency arbitrage, pro rsi divergence indicator, alongside all recommended crypto trading info alongside all my liteforex, automated forex trading reddit, automated day trading software, forex bonus 2021, algo trading on robinhood, buying and selling cryptocurrency for profit, which is also great. Finally, have a look at this awesome crypto trading tips with rofx, best platform to buy cryptocurrency, macd indicator mt4, renko automated trading ea, ig broker minimum deposit, forex robot trading system, for good measure. Check more @ Awesome Packing Machinery Info 56ef1_a
     

Chia sẻ trang này

XenForo Add-ons by Brivium ™ © 2012-2013 Brivium LLC.