zoukankan      html  css  js  c++  java
  • Android 获取自带浏览器上网记录

    先是搜索了一下,在manifest里添加

    1. <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>  


    有了这个权限就可以读取上网记录和书签了。开始时我以为只有上网记录,但是明显bookmarks是表示书签啊。而书签一般是没有时间这个内容的。所以对query语句进行了修改,添加搜索限制条件。

    1. contentResolver.query(Uri.parse("content://browser/bookmarks"), new String[] {  
    2.         "title""url""date" }, "date!=?",new String[] { "null" }, "date desc");  

    这句表示在路径“content:……bookmarks”里搜索title, url, date这三列,条件是date!=null,并按照日期降序排序。

    其实最开始的时候我是没有添加时间的,但是想想获取上网记录也关心时间,就想添加这个属性,可是发现在三星某款手机里不可以,因为一开始我搜索的时候没有添加限制条件,所以连书签都检索出来了,就像之前说的,书签是不会有时间这个属性的(这应该是一般情况)。而很奇怪的是,之前没有修改的代码在小米上就可以运行,而且只是检索出来上网记录,没有包括书签(这才是特殊情况……)。应该是小米做了修改,啊啊,android的碎片化好头疼啊。

    以下是全部代码:

      1. public class GetInternetRecord {  
      2.     String records = null;  
      3.     StringBuilder recordBuilder = null;  
      4.   
      5.     public void getRecords(ContentResolver contentResolver) {  
      6.         // ContentResolver contentResolver = getContentResolver();  
      7.         Cursor cursor = contentResolver.query(  
      8.                 Uri.parse("content://browser/bookmarks"), new String[] {  
      9.                         "title""url""date" }, "date!=?",  
      10.                 new String[] { "null" }, "date desc");  
      11.         while (cursor != null && cursor.moveToNext()) {  
      12.             String url = null;  
      13.             String title = null;  
      14.             String time = null;  
      15.             String date = null;  
      16.   
      17.             recordBuilder = new StringBuilder();  
      18.             title = cursor.getString(cursor.getColumnIndex("title"));  
      19.             url = cursor.getString(cursor.getColumnIndex("url"));  
      20.   
      21.             date = cursor.getString(cursor.getColumnIndex("date"));  
      22.   
      23.             SimpleDateFormat dateFormat = new SimpleDateFormat(  
      24.                     "yyyy-MM-dd hh:mm;ss");  
      25.             Date d = new Date(Long.parseLong(date));  
      26.             time = dateFormat.format(d);  
      27.   
      28.             System.out.println(title + url + time);  
      29.         }  
      30.     }  
      31. }  
  • 相关阅读:
    我的WCF之旅(1):创建一个简单的WCF程序
    网页设计中颜色的搭配
    CSS HACK:全面兼容IE6/IE7/IE8/FF的CSS HACK
    UVa 1326 Jurassic Remains
    UVa 10340 All in All
    UVa 673 Parentheses Balance
    UVa 442 Matrix Chain Multiplication
    UVa 10970 Big Chocolate
    UVa 679 Dropping Balls
    UVa 133 The Dole Queue
  • 原文地址:https://www.cnblogs.com/android100/p/android-get-browse.html
Copyright © 2011-2022 走看看