项目实战①—高仿知乎日报(0)-->NDK将私密数据隐藏起来
来源:互联网 发布:网络机顶盒还原出厂 编辑:程序博客网 时间:2024/05/16 08:28
①安卓程序员真的很累
②开始学NDK加入到自己的项目里面
一配置NDK环境
解压下载的android-ndk32-r10-windows-x86_64.zip,将其放到你想要的目录下。
注:R7之前的版本,必须要安装Cygwin才能使用NDK。从R7开始,Windows版本的NDK提供了一个ndk-build.cmd脚本,可以直接利用这个脚本编译。想要做到这一 点,只要为Eclipse Android工程添加一个Builder,就能实现Eclipse的自动编译NDK,这一点在后面的步骤会有介绍。
二,建立一个项目
package com.qf.teach.project.zhihudaily.c;public class API {static {System.loadLibrary("api");}/** * 主题 * @return */public static native String getThemesUrl();/** * 欢迎图片 * @return */public static native String getStartImageUrl();/** * 今日热闻 * @return */public static native String getLatestUrl();/** * 历史新闻<br /> * 返回的字符串需要使用String.format();方法格式化<br /> * 例如:String.format(API.getBefore(), "20141201"); * @return */public static native String getBefore();/** * 主题列表<br /> * 返回的字符串需要使用String.format();方法格式化<br /> * 例如:String.format(API.getTheme(), "11"); * @return */public static native String getTheme();/** * 详情 * 返回的字符串需要使用String.format();方法格式化<br /> * 例如:String.format(API.getStory(), "4354228"); * @return */public static native String getStory();/** * 详情-评论 * 返回的字符串需要使用String.format();方法格式化<br /> * 例如:String.format(API.getStoryExtra(), "4354228"); * @return */public static native String getStoryExtra();}//String.format 将指定字符串中的每个格式项替换为相应对象的值的文本等效项。
三,将NDK加入自己的项目了
1.生成java头文件
2.编写C语言代码
/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class com_xiaoxin_ZhiHuDateNews_c_API */#ifndef _Included_com_xiaoxin_ZhiHuDateNews_c_API#define _Included_com_xiaoxin_ZhiHuDateNews_c_API#ifdef __cplusplusextern "C" {#endif/* * Class: com_xiaoxin_ZhiHuDateNews_c_API * Method: getThemesUrl * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getThemesUrl (JNIEnv *, jclass);/* * Class: com_xiaoxin_ZhiHuDateNews_c_API * Method: getStartImageUrl * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getStartImageUrl (JNIEnv *, jclass);/* * Class: com_xiaoxin_ZhiHuDateNews_c_API * Method: getLatestUrl * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getLatestUrl (JNIEnv *, jclass);/* * Class: com_xiaoxin_ZhiHuDateNews_c_API * Method: getBefore * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getBefore (JNIEnv *, jclass);#ifdef __cplusplus}#endif#endif
JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getThemesUrl (JNIEnv *, jclass);
记住 加 env thiz 也就变成这样了
JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getThemesUrl (JNIEnv *env, jclass thiz){
好啦 下面就是C代码了
# include "com_xiaoxin_ZhiHuDateNews_c_API.h"JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getThemesUrl (JNIEnv *env, jclass thiz){return (*env)->NewStringUTF(env, "http://news-at.zhihu.com/api/3/themes");}JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getStartImageUrl (JNIEnv *env, jclass thiz) {return (*env)->NewStringUTF(env,"http://news-at.zhihu.com/api/3/start-image/480*728");}JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getLatestUrl (JNIEnv *env, jclass thiz) {return (*env)->NewStringUTF(env,"http://news-at.zhihu.com/api/3/stories/latest");}JNIEXPORT jstring JNICALL Java_com_xiaoxin_ZhiHuDateNews_c_API_getBefore (JNIEnv *env, jclass thiz){return (*env)->NewStringUTF(env,"http://news-at.zhihu.com/api/3/stories/before/%s");}
类里面有一个 URL 也就是我要得到的URL在里面
# Copyright (C) 2009 The Android Open Source Project## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := apiLOCAL_SRC_FILES := com_xiaoxin_ZhiHuDateNews_c_API.cinclude $(BUILD_SHARED_LIBRARY)
LOCAL_MODULE 这个是 java代码调用的类的名称,不是全类名~~~~~~~~·
3.java和c的混合编译
新建并配置一个Builder
点击Project->Properties->Builders->New,新建立一个Builder。在弹出的对话框上面点击Program,OK!如图所示
在弹出的对话框【Edit Configuration】中,配置选项卡【Main】:
Location中需要填入nkd-build.cmd的路径(NDK安装目录下)。
Working Diretcoty中需要填入TestNDK的工程根目录。如图所示:
注:不要漏了
配置选项卡【Refresh】,如图所示:
勾选“Refresh resources upon completion”,
勾选“The entire workspace”,
勾选“Recuresively include sub-folders”。
配置选项卡【Build Options】,如图七所示:
勾选“After a “Clean””,
勾选“During manual builds”,
勾选“During auto builds”,
勾选“Specify working set of relevant resources”。
点击“Specify Resources…”勾选TestNDK工程的“jni“目录 ,Finish!
- 项目实战①—高仿知乎日报(0)-->NDK将私密数据隐藏起来
- 项目实战①—高仿知乎日报(1)逼真的开场动画
- 项目实战①—高仿知乎日报(2)—>使用pullrefesh+Slidingmenu+自定义组件写主布局
- 项目实战①—高仿知乎日报(2)—>使用pullrefesh+Slidingmenu+自定义组件写主布局2
- ReactNative项目实战-仿知乎日报
- NDK探究之旅《十》——ndk项目实战之Androidstudio开发经验总结
- 【项目源码】- 【模仿知乎日报二】吐血高仿知乎日报
- 史上最强NDK入门项目实战
- 史上最强NDK入门项目实战
- ACCP4.0 [项目实战1]数据加密
- NDK探究之旅《十一》—C代码调用Java代码之项目实战
- NDK项目实战—高仿360手机助手之卸载监听
- Android 之NDK实战系列(2)——通过NDK进行简单的操作
- Android 高仿知乎日报(1)
- Android 高仿知乎日报(2)
- Android 高仿知乎日报(3)
- Android 高仿知乎日报(4)
- swift学习五天 项目实战-知乎日报之网络交互NSURLConnection
- 自定义导航条 文字大小颜色等 按钮大小图标等 背景色
- 开始记录点东西
- About me
- 男人的过错,为什么要让女人来承受
- QuickSort (MPI 实现)
- 项目实战①—高仿知乎日报(0)-->NDK将私密数据隐藏起来
- [Android设计模式]Android退出应用程序终极方法
- OJ指针当形参
- SpringMVC数据类型转换—— 注解式控制器的数据验证、类型转换及格式化
- 小功能--画一个矩形框里面贴图片
- create shortcut in gnome3 and some settings-- lockscreen & arp_attack
- Palindromes //简单字符串
- C++读取配置文件
- 【原创】《Linux高级程序设计》杨宗德著 - TCP高级应用 - 多路复用