android4.4(kitkat),如何让APP可以直接写入SMS短信
以下代码的修改是针对android平台研发的,另外如果没有系统源码的情况下,通过逆向修改ROM中的对应文件,也是可以做到的。
之所以有这样需求,是因为假如是你自己的ROM,需要对自己的某个APP授予SMS写入权限,可以通过修改如下代码中的OTHERSMS_PACKAGE_NAME,换成你自己APP的package name就可以了。
如果类似QQ通讯录这种应用,在可以获取ROOT 的权限下,能不能做到呢,我认为也是可以实现的,可以在内存中注入相关的代码片段,尝试分析了一下QQ通讯录,发现它里面在获取ROOT后,是有注入操作的,但不是实现下面的功能,QQ通讯录当前的版本在Android 4.4 (KitKat)上,仍然存在问题。
不多说了,直接上代码,自己研究喽~
diff --git a/src/java/com/android/internal/telephony/SmsApplication.java b/src/java/com/android/internal/telephony/SmsApplication.java index 0582df8..39dee4c 100644 --- a/src/java/com/android/internal/telephony/SmsApplication.java +++ b/src/java/com/android/internal/telephony/SmsApplication.java @@ -49,6 +49,7 @@ public final class SmsApplication { static final String LOG_TAG = "SmsApplication"; private static final String PHONE_PACKAGE_NAME = "com.android.phone"; private static final String BLUETOOTH_PACKAGE_NAME = "com.android.bluetooth"; + private static final String OTHERSMS_PACKAGE_NAME = "com.example.demo"; private static final String SCHEME_SMS = "sms"; private static final String SCHEME_SMSTO = "smsto"; @@ -357,6 +358,20 @@ public final class SmsApplication { // No BT app on this device Rlog.e(LOG_TAG, "Bluetooth package not found: " + BLUETOOTH_PACKAGE_NAME); } + + try { + PackageInfo info = packageManager.getPackageInfo(OTHERSMS_PACKAGE_NAME, 0); + int mode = appOps.checkOp(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid, + OTHERSMS_PACKAGE_NAME); + if (mode != AppOpsManager.MODE_ALLOWED) { + Rlog.e(LOG_TAG, OTHERSMS_PACKAGE_NAME + " lost OP_WRITE_SMS: (fixing)"); + appOps.setMode(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid, + OTHERSMS_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED); + } + } catch (NameNotFoundException e) { + // No BT app on this device + Rlog.e(LOG_TAG, "3rd sms package not found: " + OTHERSMS_PACKAGE_NAME); + } } } return applicationData;
欢迎转载:http://www.yinqisen.cn/blog-310.html
相关推荐
liuxudong00 2020-11-19
wwzaqw 2020-11-11
lihaoxiang 2020-11-05
CrossingX 2020-11-04
xuegangic 2020-10-17
fanxiaoxuan 2020-09-17
安卓猴 2020-09-12
惠秀宝 2020-09-08
wwzaqw 2020-09-04
chenyingSunny 2020-09-04
是nsacer先森的 2020-09-03
bigname 2020-08-25
gaoqiang00 2020-08-24
灵均兰草 2020-08-20
xjp 2020-08-17
webgm 2020-08-16
wiky 2020-08-05
歆萌 2020-08-03
89961330 2020-07-28