Waychel

发现一个新世界


  • 首页

  • 关于

  • 归档

WebView利用copyBackForwardList返回主页

发表于 2015-03-24
1
2
int size = webview.copyBackForwardList().getSize();
webview.goBackOrForward(size - 2*size);

WebBackForwardList copyBackForwardList():存放webview的历史记录, getsize() -> 历史记录个数

goBackOrForward:

1
2
3
4
public void goBackOrForward (int steps)

Go to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
Parameters steps The number of steps to take back or forward in the back forward list.

使用Android Studio的lint清除无用的资源文件

发表于 2015-03-23

如上图:在项目中,点击菜单栏的Analyze -> Run Inspection by Name …

弹出输入框:

Enter 之后会弹出:

一般选择整个项目或某个模块,当然也可以指定某个目录

OK之后 Studio会自动分析,然后可以根据结果清除无用的资源文件。

Note:

  1. 一般得提前删掉已经无用的java文件
  2. 接着根据分析后的结果删除 xml文件
  3. 我使用的过程,分析结果未发现图片资源文件是否可清除,所以是通过指定图片Alt+F7(Find Usages) 一张张分析删除的(累~ )

Android 保存图片并更新系统图库

发表于 2015-03-19

1.查找图库数据库是否存在该图片
2.存在则更新图片信息
3.不存在则插入图片信息到数据库
4.通知图片更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public static void savePicInfoToMediaStore(Context context,String originPath){
File file = new File(originPath);
ContentResolver contentResolver = context.getContentResolver();

ContentValues newValues = new ContentValues(6);
newValues.put(MediaStore.Images.Media.TITLE,
file.getName());
newValues.put(MediaStore.Images.Media.DISPLAY_NAME,
file.getName());
newValues.put(MediaStore.Images.Media.DATA, file.getPath());
newValues.put(MediaStore.Images.Media.DATE_MODIFIED,
System.currentTimeMillis() / 1000);
newValues.put(MediaStore.Images.Media.SIZE, file.length());
newValues.put(MediaStore.Images.Media.MIME_TYPE, "image/png");

int i = contentResolver.update(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,newValues,MediaStore.Images.Media.DATA + " =?",new String[]{originPath});
if(i == 0){//更新失败
LogUtils.e("更新失败" + i + "保存图片信息");
context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, newValues);
}

// 最后通知图库更新
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(file.getParent())));
}

webview处理302跳转

发表于 2015-02-28

在Android开发中,经常会用到webview组件,以较低的成本来展示较为复杂的图文排版。当用户点击webview中的网页的某个链接时,我们可以通过webview的shouldOverrideUrlLoading来捕获该点击,并启动自己定义好的activity或执行其它操作。该方法也同样能捕获到302重定向,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
HitTestResult hit = webView.getHitTestResult();
int hitType = hit.getType();
if (hitType == HitTestResult.SRC_ANCHOR_TYPE) {//点击超链接
//这里执行自定义的操作
return true;//返回true浏览器不再执行默认的操作
}else if(hitType == 0){//重定向时hitType为0
return false;//不捕获302重定向
}else{
return false;
}
}
});

Android JOBB

发表于 2014-06-17

官方文档:http://developer.android.com/tools/help/jobb.html

Android 2.3开始新增了一个OBB文件系统和StorageManager类用来管理外部存储上的数据安全。
jobb工具(位于 Android SDK\tools\ 目录下)允许您生成加密或不加密Opaque Binary Blob(OBB)格式的扩展文件并将之放置到APK安装文件中。你可以在Android 2.3(API 级别 9)或更高的设备上使用StorageManager下载和安装这些扩展文件到应用程序中。OBB文件可以作为Android 应用程序扩展资源文件(里面可以包含图形、声音和视频),可以独立于APK文件。

用法
jobb [-d ][-o ][-pn ][-pv ] \ [-k ][-ov][-dump ][-v][-about]

你可以使用jobb工具创建 OBB 文件或提取现有的OBB里面的内容。下面的示例命令创建一个OBB文件。

$ jobb -d /temp/assets/ -o my-app-assets.obb -k secret-key -pn com.my.app.package -pv 11

如何dump(提取)OBB的现有文件的内容:

$ jobb -d /temp/obb-output/ -o my-app-assets.obb -k secret-key

1…456…8
Waychel

Waychel

关注互联网、物联网、创业、产品、技术

36 日志
9 标签
© 2014 - 2022 Waychel
粤ICP备14032841号-1