亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android小米推送簡單使用方法

 更新時間:2017年01月24日 14:58:13   作者:木小_可ing  
這篇文章主要為大家詳細(xì)介紹了Android小米推送簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

公司項目需要做推送,我們選擇用小米推送,經(jīng)過一段時間的摸索,終于可以簡單的使用小米推送了。

1.創(chuàng)建賬號登入后 登入后選擇消息推送:


2.進入后創(chuàng)建項目,按照步驟創(chuàng)建完后如下


3.后臺配置完了,我們再配置代碼,第一次使用小米推送 我下了個Demo再把里面有用的復(fù)制到自己項目中:

先把jar包復(fù)制到自己項目中


首先在繼承了Application的類中放入

private static final String APP_ID = "2882303761517483058"; 
 // user your appid the key. 
 private static final String APP_KEY = "5951748376058"; 
 
 // 此TAG在adb logcat中檢索自己所需要的信息, 只需在命令行終端輸入 adb logcat | grep 
 // com.xiaomi.mipushdemo 
 public static final String TAG = "com.dodonew.epapp"; 

Id 和key什么的都是在小米開放平臺創(chuàng)建項目獲得的
再在Appliction的oncreate()方法中加入:

if (shouldInit()) { 
   MiPushClient.registerPush(this, APP_ID, APP_KEY); 
  } 
  LoggerInterface newLogger = new LoggerInterface() { 
 
   @Override 
   public void setTag(String tag) { 
    // ignore 
   } 
 
   @Override 
   public void log(String content, Throwable t) { 
    Log.d(TAG, content, t); 
   } 
 
   @Override 
   public void log(String content) { 
    Log.d(TAG, content); 
   } 
  }; 
  Logger.setLogger(this, newLogger); 
  if (sHandler == null) { 
   sHandler = new DemoHandler(getApplicationContext()); 
  } 

其中shouldInit()和Handler:

private boolean shouldInit() { 
  ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)); 
  List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses(); 
  String mainProcessName = getPackageName(); 
  int myPid = Process.myPid(); 
  for (RunningAppProcessInfo info : processInfos) { 
   if (info.pid == myPid && mainProcessName.equals(info.processName)) { 
    return true; 
   } 
  } 
  return false; 
 } 
 
 public static DemoHandler getHandler() { 
  return sHandler; 
 } 
 public static class DemoHandler extends Handler { 
 
  private Context context; 
 
  public DemoHandler(Context context) { 
   this.context = context; 
  } 
 
  @Override 
  public void handleMessage(Message msg) { 
   String s = (String) msg.obj; 
   if (sMainActivity != null) { 
    sMainActivity.refreshLogInfo(); 
   } 
   if (!TextUtils.isEmpty(s)) { 
    // Toast.makeText(context, s, Toast.LENGTH_LONG).show(); 
   } 
  } 
 } 

說實話Demohander其實沒什么用,主要是彈出toast提示而已,我不喜歡 于是隱藏了toast
其中MainActivity中的refreshLogInfo()方法:

public void refreshLogInfo() { 
  String AllLog = ""; 
  for (String log : logList) { 
   AllLog = AllLog + log + "\n\n"; 
  } 
  System.out.println("mainActivity中消息推送::::::::"+AllLog); 
 } 

然后 我們要把Demo中的一個廣播類復(fù)制過來 ,由于內(nèi)容一樣我就不復(fù)制了
其中有個方法很重要: onNotificationMessageClicked(Context context, MiPushMessage message)

這個方法的作用是:當(dāng)有消息推送到你手機上時 你在通知欄點擊這個消息時,就能在這個方法中通過message獲取 消息的內(nèi)容。

第二 加入你想點擊通知欄中的消息 跳轉(zhuǎn)到你app中指定的界面 也在這個方法中執(zhí)行 只需要添加一段代碼即可:

Intent intent = new Intent(context, 指定的Activity.class); 
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
  context.startActivity(intent); 

最后 我們要去配置AndroidManifest.xml
一些權(quán)限我就不放了 和以前的權(quán)限放一起了不好區(qū)分,可以去Demo中找
在權(quán)限下面放

<permission 
  android:name="com.dodonew.epapp.permission.MIPUSH_RECEIVE" 
  android:protectionLevel="signature" /> 
 
 <uses-permission android:name="com.dodonew.epapp.permission.MIPUSH_RECEIVE" /> 
 <uses-permission android:name="android.permission.VIBRATE" /> 

在<Appliction/>中添加

<service 
   android:name="com.xiaomi.push.service.XMJobService" 
   android:enabled="true" 
   android:exported="false" 
   android:permission="android.permission.BIND_JOB_SERVICE" 
   android:process=":pushservice" /> 
 
  <service 
   android:name="com.xiaomi.push.service.XMPushService" 
   android:enabled="true" 
   android:process=":pushservice" /> 
 
  <service 
   android:name="com.xiaomi.mipush.sdk.PushMessageHandler" 
   android:enabled="true" 
   android:exported="true" /> 
  <service 
   android:name="com.xiaomi.mipush.sdk.MessageHandleService" 
   android:enabled="true" /> 
 
  <receiver 
   android:name="com.dodonew.epapp.control.receiver.XiaoMiMessageReceiver" 
   android:exported="true"> 
   <intent-filter> 
    <action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /> 
   </intent-filter> 
   <intent-filter> 
    <action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /> 
   </intent-filter> 
   <intent-filter> 
    <action android:name="com.xiaomi.mipush.ERROR" /> 
   </intent-filter> 
  </receiver> 
  <receiver 
   android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver" 
   android:exported="true"> 
   <intent-filter> 
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 
 
    <category android:name="android.intent.category.DEFAULT" /> 
   </intent-filter> 
  </receiver> 
  <receiver 
   android:name="com.xiaomi.push.service.receivers.PingReceiver" 
   android:exported="false" 
   android:process=":pushservice"> 
   <intent-filter> 
    <action android:name="com.xiaomi.push.PING_TIMER" /> 
   </intent-filter> 
  </receiver> 

就可以了。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android仿硅谷商城實現(xiàn)購物車實例代碼

    Android仿硅谷商城實現(xiàn)購物車實例代碼

    這篇文章主要介紹了Android購物車編輯實現(xiàn),小編覺得挺不錯的,一起跟隨小編過來看看吧
    2018-05-05
  • 使用Fragment來處理Andoird app的UI布局的實例分享

    使用Fragment來處理Andoird app的UI布局的實例分享

    這篇文章主要介紹了使用Fragment來處理Andoird appUI布局的實例分享,Fragment的出現(xiàn)緩解了代碼依賴于Activity而造成的臃腫狀況,需要的朋友可以參考下
    2016-02-02
  • ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項的布局去綁定數(shù)據(jù)

    ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項的布局去綁定數(shù)據(jù)

    之前寫的綁定數(shù)據(jù)是只是簡單的綁定了字符串,這次我們將一次綁定多條數(shù)據(jù)并且嘗試用自定義的布局。在這篇文章中首先講解的是用Hashmap 去綁定數(shù)據(jù),第二個例子,講解自定義布局然后綁定數(shù)據(jù)
    2013-06-06
  • Android編程實現(xiàn)手機拍照的方法詳解

    Android編程實現(xiàn)手機拍照的方法詳解

    這篇文章主要介紹了Android編程實現(xiàn)手機拍照的方法,結(jié)合實例形式分析了Android實現(xiàn)手機拍照的操作步驟與具體細(xì)節(jié),需要的朋友可以參考下
    2016-11-11
  • 修改Android簽名證書keystore的密碼、別名alias以及別名密碼

    修改Android簽名證書keystore的密碼、別名alias以及別名密碼

    這篇文章主要介紹了修改Android簽名證書keystore的密碼、別名alias以及別名密碼的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • 詳解App?;顚崿F(xiàn)原理

    詳解App?;顚崿F(xiàn)原理

    一直以來,App 進程?;疃际歉鞔髲S商,特別是頭部應(yīng)用開發(fā)商永恒的追求。畢竟App 進程死了,就什么也干不了了;一旦 App 進程死亡,那就再也無法在用戶的手機上開展任何業(yè)務(wù),所有的商業(yè)模型在用戶側(cè)都沒有立足之地
    2021-06-06
  • Android實現(xiàn)圖片上傳蒙層進度條

    Android實現(xiàn)圖片上傳蒙層進度條

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)圖片上傳蒙層進度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • gradle中的properties文件詳解

    gradle中的properties文件詳解

    這篇文章主要介紹了gradle中的properties文件詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法

    Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法

    這篇文章主要介紹了Android實現(xiàn)從網(wǎng)絡(luò)獲取圖片顯示并保存到SD卡的方法,涉及Android操作多媒體文件及系統(tǒng)硬件設(shè)備的相關(guān)技巧,需要的朋友可以參考下
    2015-12-12
  • Android對圖片Drawable實現(xiàn)變色示例代碼

    Android對圖片Drawable實現(xiàn)變色示例代碼

    這篇文章主要給大家介紹了關(guān)于Android對圖片Drawable實現(xiàn)變色的相關(guān)資料,文中通過示例代碼將實現(xiàn)的方法介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-08-08

最新評論