導航:首頁 > 操作系統 > android通知demo

android通知demo

發布時間:2025-05-06 14:59:17

android demo是什麼意思

游戲中的「DEMO」 在游戲正式版發售之前,官方為了進行宣傳和壓力測試,而放出的不完全版本,通常稱為「試玩版」。

開發中 DEMO 是列子開發, 不知道是不是你想要的

⑵ android開發支付寶付款實時通知是怎麼實現的

到支付寶官網,下載支付寶集成開發包,看懂裡面的關鍵代碼

由於android設備一般用的都是無線支付,所有我們申請的就是支付寶無線快捷支付介面。


如果鏈接失效,你可以到支付寶官網商家服務模塊中找到 快捷支付(無線)這個服務。

下載集成開發包,解壓發現裡面有客戶端的demo即說明文檔,在客戶端的demo中找到Android_SDK,這個就是你要用到的支付寶介面及demo。


把demo(alipay_sdk_demo)和(alipay_lib)導入到你的eclipse裡面,然後你可以試著運行一遍demo(alipay_sdk_demo),只要把這個demo搞懂了,你就會調用這個支付寶介面了。至於到時候如何集成到你的項目裡面,文檔上說明很詳細,按著文檔上一步一步來就行了。我的建議是先把這個demo弄懂再設計你的項目,看看調用介面時需要哪些數據,這樣也有利於你一開始設計數據。

下面來簡單的介紹下介面demo裡面的結構。

你打開項目會發現裡面有5個類。

java">kagecom.alipay.android.msp.demo;

importjava.io.IOException;
........
........
importcom.alipay.android.app.sdk.AliPay;

,
OnClickListener{
publicstaticfinalStringTAG="alipay-sdk";

privatestaticfinalintRQF_PAY=1;

privatestaticfinalintRQF_LOGIN=2;

privateEditTextmUserId;
privateButtonmLogon;

@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.external_partner);

initProcts();
initListView();
}

/*
*(non-Javadoc)
*
*@seeandroid.app.Activity#onCreateOptionsMenu(android.view.Menu)
*/
@Override
(Menumenu){
menu.add(Menu.NONE,Menu.FIRST,1,"快速登錄");
returntrue;
}

/*
*(non-Javadoc)
*
*@seeandroid.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
(MenuItemitem){
switch(item.getItemId()){
caseMenu.FIRST:
setContentView(R.layout.trustlogin);
mUserId=(EditText)findViewById(R.id.user_id);
mLogon=(Button)findViewById(R.id.get_token);
mLogon.setOnClickListener(this);
break;
}
returnfalse;
}

privatevoidinitProcts(){
if(sProcts!=null)
return;

XmlResourceParserparser=getResources().getXml(R.xml.procts);
ArrayList<Proct>procts=newArrayList<Proct>();
Proctproct=null;

try{
inteventType=parser.getEventType();

while(eventType!=XmlPullParser.END_DOCUMENT){
if(eventType==XmlPullParser.START_TAG
&&parser.getName().equalsIgnoreCase("proct")){
proct=newProct();
proct.subject=parser.getAttributeValue(0);
proct.body=parser.getAttributeValue(1);
proct.price=parser.getAttributeValue(2);
procts.add(proct);
}
eventType=parser.next();
}

sProcts=newProct[procts.size()];
procts.toArray(sProcts);

}catch(XmlPullParserExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
}
//listview點擊事件,裡面調用的支付寶介面
@Override
publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intposition,
longarg3){
try{
Log.i("ExternalPartner","onItemClick");
Stringinfo=getNewOrderInfo(position);//這個是訂單信息
Stringsign=Rsa.sign(info,Keys.PRIVATE);//簽名加密訂單信息什麼的
sign=URLEncoder.encode(sign);
info+="&sign=""+sign+""&"+getSignType();
Log.i("ExternalPartner","startpay");
//startthepay.
Log.i(TAG,"info="+info);

finalStringorderInfo=info;
newThread(){
publicvoidrun(){
AliPayalipay=newAliPay(ExternalPartner.this,mHandler);//這個應該就是支付寶介面了,哈哈,支付寶現在把很多功能都封裝了,所以省了很多代碼

//設置為沙箱模式,不設置默認為線上環境
//alipay.setSandBox(true);

Stringresult=alipay.pay(orderInfo);//這個是返回的結果,你到時候可以根據這個結果加以操作你想操作的,然後基本就完了,其他的你想附加的功能你看著寫吧,現在Key.java配置好就能調用快捷支付了
//後面的這些代碼可以改成你自己的,也可以在它們的基礎上改
Log.i(TAG,"result="+result);
Messagemsg=newMessage();
msg.what=RQF_PAY;
msg.obj=result;
mHandler.sendMessage(msg);
}
}.start();

}catch(Exceptionex){
ex.printStackTrace();
Toast.makeText(ExternalPartner.this,R.string.remote_call_failed,
Toast.LENGTH_SHORT).show();
}
}
//獲得訂單信息的方法
privateStringgetNewOrderInfo(intposition){
StringBuildersb=newStringBuilder();
sb.append("partner="");
sb.append(Keys.DEFAULT_PARTNER);//合作身份者id
sb.append(""&out_trade_no="");
sb.append(getOutTradeNo());//這個是訂單編號
sb.append(""&subject="");
sb.append(sProcts[position].subject);//這個應該是商品名稱
sb.append(""&body="");
sb.append(sProcts[position].body);//這個應該是商品的描述,具體你可以參考demo
sb.append(""&total_fee="");
sb.append(sProcts[position].price.replace("一口價:",""));//這個是要付款的金額,到時候你調用的時候改下就行了
sb.append(""¬ify_url="");
//網址需要做URL編碼
sb.append(URLEncoder.encode("http://notify.java.jpxx.org/index.jsp"));//伺服器非同步通知頁面,完成交易後通知商家伺服器的頁面,以post的形式將商品訂單信息發送到指定頁面,手機客戶端不需要可以先放在這不管。是不是,這個類很簡單看懂吧,就一listview。調用支付寶介面的方法就在onItemClick()方法裡面,如果你是一個按鈕的話換成按鈕點擊事件就行了,主要的細節我注釋已寫。現在你要想的是,需要哪些數據,提供給onItemClick()方法裡面的Stringinfo。demo裡面的數據是getNewOrderInfo(intposition)這個方法提供的,你可以自己提供或者在上面修改下。
現在,你已經知道代碼是如何調用支付寶介面了。接下來,是如何把這些集成到你的項目中去。

⑶ android 怎麼通知欄消息

//消息通知欄
//定義NotificationManager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
//定義通知欄展現的內容信息
int icon = R.drawable.icon;
CharSequence tickerText = "我的通知欄標題";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

//定義下拉通知欄時要展現的內容信息
Context context = getApplicationContext();
CharSequence contentTitle = "我的通知欄標展開標題";
CharSequence contentText = "我的通知欄展開詳細內容";
Intent notificationIntent = new Intent(this, BootStartDemo.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);

//用mNotificationManager的notify方法通知用戶生成標題欄消息通知
mNotificationManager.notify(1, notification);

⑷ android通知欄怎麼添加控制項

Notification的自定義布局是RemoteViews,和其他RemoteViews一樣,在自定義視圖布局文件中,僅支持FrameLayout、LinearLayout、RelativeLayout三種布局控制項和AnalogClock、Chronometer、Button、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper、ListView、GridView、StackView和AdapterViewFlipper這些顯示控制項,不支持這些類的子類或Android提供的其他控制項。否則會引起ClassNotFoundException異常

步驟如下:

1)創建自定義視圖

2)獲取遠程視圖對象(註:Notification的contentView不能為空)

3)設置PendingIntent(來響應各種事件)

4)發起Notification

大體4步驟這里就不詳細說了,下面就把DEMO中的列子拿出來說下

樣式:

1.自定義帶按鈕通知欄(如下樣式)

正在進行的

「正在進行的」通知使用戶了解正在運行的後台進程。例如,音樂播放器可以顯示正在播放的音樂。也可以用來顯示需要長時間處理的操作,例如下載或編碼視頻。「正在進行的」通知不能被手動刪除。

實現方法如下:

實現方法如下:
/**
*帶按鈕的通知欄
*/
publicvoidshowButtonNotify(){
NotificationCompat.BuildermBuilder=newBuilder(this);
RemoteViewsmRemoteViews=newRemoteViews(getPackageName(),R.layout.view_custom_button);
mRemoteViews.setImageViewResource(R.id.custom_song_icon,R.drawable.sing_icon);
//API3.0以上的時候顯示按鈕,否則消失
mRemoteViews.setTextViewText(R.id.tv_custom_song_singer,"周傑倫");
mRemoteViews.setTextViewText(R.id.tv_custom_song_name,"七里香");
//如果版本號低於(3。0),那麼不顯示按鈕
if(BaseTools.getSystemVersion()<=9){
mRemoteViews.setViewVisibility(R.id.ll_custom_button,View.GONE);
}else{
mRemoteViews.setViewVisibility(R.id.ll_custom_button,View.VISIBLE);
}
//
if(isPlay){
mRemoteViews.setImageViewResource(R.id.btn_custom_play,R.drawable.btn_pause);
}else{
mRemoteViews.setImageViewResource(R.id.btn_custom_play,R.drawable.btn_play);
}
//點擊的事件處理
IntentbuttonIntent=newIntent(ACTION_BUTTON);
/*上一首按鈕*/
buttonIntent.putExtra(INTENT_BUTTONID_TAG,BUTTON_PREV_ID);
//這里加了廣播,所及INTENT的必須用getBroadcast方法
PendingIntentintent_prev=PendingIntent.getBroadcast(this,1,buttonIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_prev,intent_prev);
/*播放/暫停按鈕*/
buttonIntent.putExtra(INTENT_BUTTONID_TAG,BUTTON_PALY_ID);
PendingIntentintent_paly=PendingIntent.getBroadcast(this,2,buttonIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_play,intent_paly);
/*下一首按鈕*/
buttonIntent.putExtra(INTENT_BUTTONID_TAG,BUTTON_NEXT_ID);
PendingIntentintent_next=PendingIntent.getBroadcast(this,3,buttonIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_next,intent_next);

mBuilder.setContent(mRemoteViews)
.setContentIntent(getDefalutIntent(Notification.FLAG_ONGOING_EVENT))
.setWhen(System.currentTimeMillis())//通知產生的時間,會在通知信息里顯示
.setTicker("正在播放")
.setPriority(Notification.PRIORITY_DEFAULT)//設置該通知優先順序
.setOngoing(true)
.setSmallIcon(R.drawable.sing_icon);
Notificationnotify=mBuilder.build();
notify.flags=Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(notifyId,notify);
}

如果您對回答滿意,請關注一下俺的微博

閱讀全文

與android通知demo相關的資料

熱點內容
php小數位數 瀏覽:383
pt100濕度感測器單片機 瀏覽:302
如何判斷伺服器運行慢 瀏覽:915
汽車貸款沒壓綠本需要解壓嘛 瀏覽:186
安卓如何實現單選 瀏覽:646
javanewfile編譯後找不到文件 瀏覽:851
盒馬app積分在哪裡看 瀏覽:504
怎麼把安卓轉到電腦 瀏覽:54
安卓怎麼查產生的圖片 瀏覽:26
看貓和老鼠用什麼app好 瀏覽:994
排列窗口命令圖片 瀏覽:201
製作公章怎麼加密 瀏覽:535
阿里雲伺服器秒殺價格表 瀏覽:109
空調壓縮機過濾器堵塞 瀏覽:911
編譯器和感測器 瀏覽:425
全什麼配音app 瀏覽:115
新氧app是干什麼的 瀏覽:376
什麼app可以免費下載小說 瀏覽:64
pgp桌面加密 瀏覽:99
java多線程編程視頻 瀏覽:663