我想实现一个基本的想法,在android中制作资产负债表.如果我在我的号码拨号屏幕上写*#*#1234#*#*,那么它必须在我的应用程序中增加34(或者可能在文本文件中).为了实现这个想法,我遇到了android.provider.Telephony.SECRET_CODE.
我想要的是从手机的拨号盘读取任何数字,如*#*#< number>#*#*.因此,我希望我的代码以某种方式运行,以便将此格式的任何代码标识为密码:*#*#12 $$#*#*.我想很难想象它是否有任何可行的方法,但如果有人知道的话,我会非常好奇地知道.非常感谢提前!
解决方法:
http://blog.udinic.com/2013/05/17/create-a-secret-doorway-to-your-app
检查此链接.
这是一段代码示例.在您的清单中,声明您的接收器并使用密码,例如:111222
<receiver android:name=".receiver.DiagnoserReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data android:scheme="android_secret_code" android:host="111222"/>
</intent-filter>
</receiver>
然后创建接收器:
public class DiagnoserReceiver extends broadcastReceiver {
public void onReceive(Context context, Intent intent) {
if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
//Do your increment here
}
}
}
我想如果你想要多个数字,你可以添加你的应用会监听的代码变体:
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data android:scheme="android_secret_code" android:host="111222"/>
<data android:scheme="android_secret_code" android:host="1234"/>
<data android:scheme="android_secret_code" android:host="1235"/>
<data android:scheme="android_secret_code" android:host="1236"/>
<data android:scheme="android_secret_code" android:host="1237"/>
</intent-filter>
编辑:
你可以试试这个SO post I found
only to match the beginning of host. The rules are these:
android:host="*site.com"
android:pathPattern=".*"
android:scheme="http" />
It will catch links of:
- www.site.com
- site.com
- mail.site.com
所以你应该能够通配符的字体
<data android:scheme="android_secret_code" android:pathPattern="*" android:host="*34"/>
理论上它应该适用于0034 … 9934
**小心:**
任何人都可以反编译您的应用并查看清单文件中的代码.所以无论你做什么,都要确保它是安全的. IE浏览器.如果您从接收方打开活动,请确保活动首先要求输入密码.