Android:获取APK签名信息 .

获取Android APK包签名信息及PC上Java代码实现
本文详细介绍了如何使用命令行工具jarsigner-verify-verbose-certs获取Android应用APK包的签名信息,并通过Java代码在PC上实现此功能。包括从keystore中获取指纹信息的方法,以及在不同开发环境下操作APK文件的基本步骤。

1、使用命令获取Android的APK包签名信息

  1. jarsigner -verify -verbose -certs <your_apk_path.apk>

对于一个keystore的指纹信息获取可以用如下命令:

  1. D:/>keytool -list -alias alias_name -keystore keystore_name.KEYSTORE
  2. 输入keystore密码:
  3. sodino_keystore, 2010-8-9, PrivateKeyEntry,
  4. 认证指纹 (MD5): CB:5E:F5:33:23:F4:D2:D3:CC:74:9D:BF:14:36:EB:8D

2、PC上使用java代码获取APK信息:

可以参考http://zhuq0516-struts2.googlecode.com/svn/

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal"> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" /> <uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc.hce" android:required="false" /> <uses-feature android:name="android.hardware.nfc" android:required="false" /> <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:hardwareAccelerated="true"> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- 添加NFC处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter> <!-- 添加深度链接处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="xl" android:host="goods" android:port="8888" android:pathPrefix="/goodsDetail" /> </intent-filter> </activity> </application> </manifest> 这是我现在的xml文件,我的应用包名为com.example.text 我该怎么更改,并使用什么URL去启动应用并传递数据
最新发布
08-07
<think>我们正在配置Android应用的深度链接(Deep Link),以便通过特定的URL启动应用(包名为com.example.text)并传递数据。 在AndroidManifest.xml中,我们需要在启动Activity(通常是MainActivity)中添加<intent-filter>来捕获深度链接。 根据引用[1]中的示例,深度链接的格式如:peopleapp://people/0,我们可以使用自定义的scheme(例如:myapp)和host(可选)来定义我们的URL。 步骤: 1.AndroidManifest.xml中,为想要处理深度链接的Activity(例如MainActivity)添加一个<intent-filter>。 2. 在<intent-filter>中,设置<action>为android.intent.action.VIEW,这样该Activity就可以被隐式调用来显示数据。 3. 添加<category>:android.intent.category.DEFAULT(允许在没有明确指定类别的情况下被调用)和android.intent.category.BROWSABLE(允许从Web浏览器中调用)。 4. 使用<data>元素定义URL的格式,包括scheme和host(可选)。例如,如果我们希望深度链接的格式为:myapp://example.com/path?param=value,那么我们可以设置: android:scheme="myapp" android:host="example.com" android:pathPrefix="/path" (可选,如果不需要特定路径可以省略) 注意:如果不想限定host,可以设置android:host为任意值,比如"*"(但不推荐,因为可能与其他应用冲突),或者更常见的做法是设置一个特定的host(如应用官网域名)。 5. 为了在应用启动时获取传递过来的数据,我们需要在Activity中解析Intent。 修改后的AndroidManifest.xml示例:</think>### AndroidManifest.xml 深度链接配置指南 以下是配置深度链接的完整解决方案,用于通过特定URL启动应用 `com.example.text` 并传递数据: #### 1. 基本配置(修改 `AndroidManifest.xml`) ```xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.text"> <application> <!-- 主Activity配置 --> <activity android:name=".MainActivity"> <!-- 深度链接配置 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- 自定义URL方案 --> <data android:scheme="myapp" android:host="open" android:pathPrefix="/data" /> </intent-filter> <!-- 可选:添加备用方案 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" android:host="example.com" android:pathPrefix="/open" /> </intent-filter> </activity> </application> </manifest> ``` #### 2. 配置说明 | 属性 | 值 | 说明 | |------|----|------| | `android:scheme` | `myapp` | 自定义URL协议头(如 `myapp://`) | | `android:host` | `open` | URL主机名(如 `myapp://open`) | | `android:pathPrefix` | `/data` | URL路径前缀(如 `myapp://open/data`) | #### 3. 支持的URL格式 ```plaintext myapp://open/data?id=123&name=test https://example.com/open/data?param=value ``` #### 4. Activity中获取数据(Java示例) ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleDeepLink(getIntent()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); handleDeepLink(intent); } private void handleDeepLink(Intent intent) { if (intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW)) { Uri data = intent.getData(); if (data != null) { // 获取完整URL String url = data.toString(); // 解析参数 String id = data.getQueryParameter("id"); String name = data.getQueryParameter("name"); // 业务处理 processDeepLinkData(id, name); } } } private void processDeepLinkData(String id, String name) { // 实际业务逻辑 } } ``` #### 5. 测试方法 使用ADB命令测试深度链接: ```bash # 测试自定义scheme adb shell am start -a android.intent.action.VIEW -d "myapp://open/data?id=123&name=test" com.example.text # 测试HTTP链接 adb shell am start -a android.intent.action.VIEW -d "https://example.com/open/data?param=value" com.example.text ``` #### 6. 高级配置(可选) ```xml <!-- 添加多路径支持 --> <intent-filter> ... <data android:scheme="myapp" android:host="open" android:pathPattern="/data/.*" /> </intent-filter> <!-- 添加MIME类型支持 --> <intent-filter> ... <data android:mimeType="application/vnd.example.text" /> </intent-filter> ``` #### 7. 安全建议 1. **验证来源**: ```java if (!"example.com".equals(data.getHost())) { // 拒绝非信任来源 } ``` 2. **参数签名验证**: ```java String signature = data.getQueryParameter("sig"); if (!validateSignature(data, signature)) { // 拒绝无效签名 } ``` 3. **防止参数注入**: ```java String param = URLDecoder.decode(rawParam, "UTF-8") .replaceAll("[^a-zA-Z0-9_]", ""); ``` > **注意**:对于Android 12+,需添加[`<queries>`](https://developer.android.com/training/package-visibility)声明才能与其他应用交互[^1][^3]。 --- ### 相关问题 1. 如何在Android应用中处理多个深度链接路径? 2. 深度链接参数如何进行安全加密? 3. Android 12+ 对深度链接有哪些新限制? 4. 如何实现iOS平台的深度链接配置? 5. 深度链接在应用未安装时如何跳转到应用商店? 6. 如何处理特殊字符在URL参数中的传递问题? [^1]: 深度链接URL格式参考 [^2]: 数据持久化与安全处理 [^3]: Android 12+ 包可见性要求
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值