欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

掃二維碼下載apk并統(tǒng)計(jì)被掃描次數(shù)

 更新時(shí)間:2017年01月03日 10:24:56   作者:Joanna.Yan  
本文主要對(duì)實(shí)現(xiàn)用戶掃描一個(gè)二維碼就能下載APP,并統(tǒng)計(jì)被掃描次數(shù)的方法進(jìn)行詳細(xì)介紹,具有一定的參考作用,下面跟著小編一起來(lái)看下吧

需求:想讓用戶掃描一個(gè)二維碼就能下載APP,并統(tǒng)計(jì)被掃描次數(shù)。

兩種實(shí)現(xiàn)方法:

1.一般我們用草料生成二維碼,如果沒(méi)有注冊(cè)的話只能生成一個(gè)包含下載網(wǎng)址的靜態(tài)碼,沒(méi)有統(tǒng)計(jì)功能,而且出了自己截圖保存外,草料是不會(huì)保存你的二維碼的。

如果注冊(cè)草料后,可以選擇生成活碼。所謂活碼,就是一個(gè)指向頁(yè)面,然后通過(guò)這個(gè)指向頁(yè)面,再到你的下載鏈接。這個(gè)指向頁(yè)面內(nèi)嵌了統(tǒng)計(jì)代碼。你可以通過(guò)草料的統(tǒng)計(jì)功能,看你的二維碼相關(guān)的掃描數(shù)據(jù)。

2.你的App下載地址,自己內(nèi)嵌一個(gè)統(tǒng)計(jì)代碼,這樣來(lái)統(tǒng)計(jì)掃描數(shù)據(jù),這樣,你只要一個(gè)靜態(tài)碼就夠了。不需要在草料注冊(cè),用戶掃描二維碼后,直接進(jìn)入下載界面,沒(méi)有中間的指向頁(yè)面。

由于不希望自己的app投放到應(yīng)用市場(chǎng),因此微下載行不通。比如,把你的APK文件上傳到騰訊的開(kāi)放平臺(tái),申請(qǐng)通過(guò)后,會(huì)拿到一個(gè)移動(dòng)推廣鏈接,然后替換原來(lái)的“android下載”的鏈接(直接此文件生成一個(gè)二維碼也行),這樣用戶就可以在微信中掃一掃直接下載了。

同時(shí),一般用戶用掃一掃,大多都用微信自帶“掃一掃”工具,而微信打開(kāi)的二維碼頁(yè)面,會(huì)自動(dòng)屏蔽apk文件,所有顯然把a(bǔ)pk的url生成一個(gè)二維碼,讓用戶掃一掃后就能直接下載,這樣是行不通的。微信做了限制除了和微信有合作關(guān)系的應(yīng)用才能使用微信掃描后直接下載apk,其他的應(yīng)用只能點(diǎn)擊微信右上角的菜單跳轉(zhuǎn)到普通瀏覽器下載apk。

嘗試:

用草料生成二維碼:

“文件”方式生成二維碼:上傳需要下載的文件,生成二維碼,掃描二維碼跳轉(zhuǎn)到它默認(rèn)的模板頁(yè)面,點(diǎn)擊可下載該文件。但是不支持.apk這樣的特殊格式。

“網(wǎng)址”方式生成二維碼:直接將.apk的下載地址url生成二維碼,掃描下載行不通。微信將其屏蔽了(QQ中的“掃一掃”功能是可以的,易信、360也都可以掃出來(lái))。

所以最終采用第二種方法。

實(shí)現(xiàn)方案:

直接判斷微信的ua,然后彈出一個(gè)遮罩提示用戶在新的瀏覽器中打開(kāi)下載,并且加關(guān)閉的按鈕,類似于如圖。

(1)在你的服務(wù)器上寫一個(gè)下載詳情頁(yè)面,將app下載鏈接放上去。這里設(shè)計(jì)的是:使用JS+HTML+CSS結(jié)合的方式,用移動(dòng)h5技術(shù)適配了手機(jī)版網(wǎng)頁(yè),不會(huì)在已進(jìn)入微信就彈出提示它在新瀏覽器中打開(kāi),因?yàn)槟氵€可以在這個(gè)頁(yè)面里做一些提交表單查看信息等操作。只有用戶點(diǎn)擊應(yīng)用下載鏈接才彈出遮罩提示跳轉(zhuǎn)至新的瀏覽器下載,如圖:

(2)把下載頁(yè)面的URL地址,通過(guò)"草料二維碼"生成一個(gè)二維碼,如圖:

(3)如果是在微信里掃一掃打開(kāi)的,當(dāng)用戶點(diǎn)擊“安卓版下載”的時(shí)候,就提示用戶要在默認(rèn)瀏覽器中打開(kāi),如圖:

(4)其實(shí)掃描二維碼,就是訪問(wèn)一個(gè)url,可以在后臺(tái)統(tǒng)計(jì)url被訪問(wèn)的次數(shù),就是掃描二維碼的次數(shù)了。

 貼出關(guān)鍵代碼:

 public class Counter{
 private int count; 
 public Counter(){
  this(0);
  }
 public Counter(int count){
  this.count=count;
  }
 public void setCount(int count){
  this.count=count;
  }
 public int getCount(){
  return count;
  }
 public void add(int step){
  count+=step;
  }
 }
 /**
 * 統(tǒng)計(jì)頁(yè)面訪問(wèn)的次數(shù),并在關(guān)閉應(yīng)用時(shí)將其保存到文件,待下次啟應(yīng)用時(shí)讀取次數(shù)。
 * @author Joanna.Yan
 *
 */
public class MyServletContextListener implements ServletContextListener{
 public void contextInitialized(ServletContextEvent sce){
  System.out.println("====================helloapp application is Initialized.==========");
  ServletContext context=sce.getServletContext();
  try{
   BufferedReader reader = new BufferedReader(
     new InputStreamReader(context.getResourceAsStream("/count/count.txt")));
   int count = Integer.parseInt(reader.readLine());
   reader.close();
   Counter counter = new Counter(count);
   context.setAttribute("counter",counter);
  }catch(IOException e){e.printStackTrace();}
  }
 public void contextDestroyed(ServletContextEvent sce){
  System.out.println("helloapp application is Destroyed.");
  ServletContext context=sce.getServletContext();
  Counter counter=(Counter)context.getAttribute("counter");
  if(counter != null){
   try{
    String filepath = context.getRealPath("/count");
    filepath = filepath+"/count.txt";
    PrintWriter pw= new PrintWriter(filepath);
    pw.println(counter.getCount());
    pw.close();
   }catch(IOException e){e.printStackTrace();};
   }
  }
 }

web.xml中注冊(cè)監(jiān)聽(tīng)器:

<listener>
 <listener-class>joanna.yan.listener.MyServletContextListener</listener-class>
 </listener>

web.xml中注冊(cè)servlet:

<servlet>
 <servlet-name>QRCodeServlet</servlet-name>
 <servlet-class>joanna.yan.servlet.QRCodeServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>QRCodeServlet</servlet-name>
 <url-pattern>/QRCode</url-pattern>
 </servlet-mapping>
public class QRCodeServlet extends HttpServlet{
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  doPost(req, resp);
 }
 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  System.out.println("QRCodeServlet被訪問(wèn)了!");
  ServletContext context=getServletContext();
  Counter counter=(Counter) context.getAttribute("counter");
  if(counter==null){
   counter=new Counter(1);
   context.setAttribute("counter", counter);
  }
  counter.add(1);
  System.out.println("被掃描的次數(shù):"+counter.getCount());
  resp.sendRedirect(""+req.getContextPath()+"/apkdownload.jsp");
 }
}

設(shè)置適配移動(dòng)端屏幕,禁止瀏覽器的縮放功能:

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">

CSS+JS:

<style type="text/css">
  #weixin-tip{display:none;position:fixed;left:0;top:0;background:rgba(0,0,0,0.8);filter:alpha(opacity=80);width:100%;height:100%;z-index:100;}
  #weixin-tip p{text-align:center;margin-top:10%;padding:0 5%;position:relative;}
  #weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:5%;}
</style>
 <script type="text/javascript">
  var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1;})();
  window.onload = function() {
  var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight; //兼容IOS,不需要的可以去掉
  var btn = document.getElementById('J_weixin');
  var tip = document.getElementById('weixin-tip');
  var close = document.getElementById('close');
  if (is_weixin) {
   btn.onclick = function(e) {
    tip.style.height = winHeight + 'px'; //兼容IOS彈窗整屏
    tip.style.display = 'block';
    return false;
   };
   close.onclick = function() {
    tip.style.display = 'none';
   };
  }
 }; 
 </script>
....你的網(wǎng)頁(yè)代碼......
 <div id="weixin-tip">
   <p>
   <img alt="微信打開(kāi)" src="img/warn.png">
   <span id="close" title="關(guān)閉" class="close">X</span>
   </p>
 </div>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論