国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2019-12-12 04:09:11
字體:
供稿:網(wǎng)友

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

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

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

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

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

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

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

嘗試:

用草料生成二維碼:

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

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

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

實現(xiàn)方案:

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

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

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

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

(4)其實掃描二維碼,就是訪問一個url,可以在后臺統(tǒng)計url被訪問的次數(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)計頁面訪問的次數(shù),并在關(guān)閉應(yīng)用時將其保存到文件,待下次啟應(yīng)用時讀取次數(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中注冊監(jiān)聽器:

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

web.xml中注冊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被訪問了!");  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è)置適配移動端屏幕,禁止瀏覽器的縮放功能:

<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)頁代碼...... <div id="weixin-tip">   <p>   <img alt="微信打開" src="img/warn.png">   <span id="close" title="關(guān)閉" class="close">X</span>   </p> </div>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持武林網(wǎng)!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 天峨县| 华亭县| 承德县| 色达县| 漳浦县| 平山县| 勐海县| 长海县| 营山县| 元氏县| 将乐县| 宜宾县| 开江县| 金湖县| 临湘市| 哈巴河县| 乌拉特前旗| 登封市| 宜都市| 泸溪县| 阿坝县| 鹤庆县| 西峡县| 宁波市| 景谷| 古浪县| 和平县| 太康县| 庆城县| 敦化市| 镶黄旗| 板桥市| 巩义市| 社旗县| 远安县| 长丰县| 铜山县| 定兴县| 离岛区| 潮州市| 泰兴市|