我正在寻找一种方法来挂钩SMSManager或更低级别的机制,这样我就可以拦截,阅读并取消发送之前的任何传出的SMS消息。拦截,阅读和取消短信
4
A
回答
11
很明显,这不是你想听到的,但是Android的设计根本不是允许第三方应用程序互相干扰或者超越用户的自由选择。
它没有提供一个“hook”类型的机制来强制拦截基本功能,而不是修改安装在设备上的Android本身的内部版本。
设备管理员界面不包含管理短信的任何内容。
是的,有时候人们会使用各种“黑客”方法在某种程度上完成这些事情,但它们与平台的设计相悖,因此或者在不同的“错误修复”类型改进时不可靠或可能中断是由android制作的。或者他们的范围受到限制,例如更换主屏幕,从而限制轻松启动的内容 - 但只有在主屏幕应用程序保持选定状态,并且无法规范其他意图源的情况下。
您可能会发现在头脑的思想足够的吸引力,你决定要运行它,但记住,除非它是一个未来的介绍打算做这种事情的API 你最有可能被利用的监督,很可能会很快纠正平台的设计。
3
妥协怎么样?为什么不创建一个应用程序来写短信?用户可以选择它作为写短信的默认应用程序,所以它不会一直困扰他们。我相信,只有这样,才能实现接近您的目标而无需生根/提供您自己的Android版本。
+0
是的,我想避免这样做,但我同意它似乎是唯一可行的方法。 – Tom 2011-08-10 11:19:21
7
犹未晚之后再也没有:)
我把时间用在这2个天... ...而且不希望其他任何浪费自己的时间:)
- 拨打服务,以及注册内容观察者在服务类
UPDATE:加入SMS模型类
public class SMS {
public Date date;
public String from;
public String message;
public String to;
public SMS(String paramString1, String paramString2, String paramString3,Date paramDate) {
this.from = paramString1;
this.to = paramString2;
this.message = paramString3;
this.date = paramDate;
}
}
public class ServiceClass extends Service implements SMSListener {
public static boolean sendSms = true;
private final IBinder mBinder = new LocalBinder();
public static MyContentObserver mSMSObserver;
private Context ctx;
public static SMS param_SMS;
int myID = -1;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
myID = startId;
sendSms = true;
Context localContext = getApplicationContext();
ctx = localContext;
mSMSObserver = new MyContentObserver(null);
mSMSObserver.setSMSListener(this);
mSMSObserver.start(localContext);
return Service.START_STICKY;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
SharedPreferences prefs = getApplicationContext().getSharedPreferences(
"appData", 0);
if (prefs.getBoolean(CommonStrings.KEY_PREFS_TOGGLE, false)) {
super.onDestroy();
Log.e("OnDestroy", "Stopping Service");
Context localContext = getApplicationContext();
mSMSObserver.stop(localContext);
try {
stopSelf(myID);
Log.e("Stopping self", "Stopping Service");
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Log.e("OnBinder", "OnBinder");
return null;
}
@Override
public void reportIncomingSms(SMS paramSMS) {
// TODO Auto-generated method stub
}
public void reportOutgoingSms(SMS paramSMS) {
if (!MainActivity.stopped) {
Log.e("OUT GOING SMS DETECTED", "OUT GOING SMS DETECTED");
sendSms = true;
param_SMS = paramSMS;
// DO ANY THING, Out going Msg detected...
}
}
public class LocalBinder extends Binder {
public LocalBinder() {
}
public ServiceClass getService() {
return ServiceClass.this;
}
}
}
扩展内容观察员
public class MyContentObserver extends ContentObserver { public static final int MESSAGE_TYPE_ALL = 0; public static final int MESSAGE_TYPE_DRAFT = 3; public static final int MESSAGE_TYPE_FAILED = 5; public static final int MESSAGE_TYPE_INBOX = 1; public static final int MESSAGE_TYPE_OUTBOX = 4; public static final int MESSAGE_TYPE_QUEUED = 6; public static final int MESSAGE_TYPE_SENT = 2; public static final String TYPE = "type"; private SMSListener mSMSListener; public static long _id; private ContentObserver observer; public MyContentObserver(Handler handler) { super(handler); // TODO Auto-generated constructor stub } private void readFromOutgoingSMS(Context paramContext) { if (!MainActivity.stopped) { Cursor localCursor = paramContext.getContentResolver().query( Uri.parse("content://sms"), null, null, null, null); long l = 0; int i; if (localCursor.moveToNext()) { l = localCursor.getLong(localCursor.getColumnIndex("_id")); String str1 = localCursor.getString(localCursor .getColumnIndex("protocol")); i = localCursor.getInt(localCursor.getColumnIndex("type")); if ((str1 != null) || (i != 6)) localCursor.close(); if (i == 6) { int j = localCursor.getColumnIndex("body"); int k = localCursor.getColumnIndex("address"); Date localDate = new Date(localCursor.getLong(localCursor .getColumnIndex("date"))); String str2 = localCursor.getString(k); String str3 = localCursor.getString(j); localCursor.close(); _id = l; // Delete SMS and Save the sms content to custom type variable if (deleteSms(paramContext, l)) { SMS localSMS = new SMS("", str2, str3, localDate); this.mSMSListener.reportOutgoingSms(localSMS); } else { localCursor.close(); } } } } } public static boolean deleteSms(Context paramContext, long paramLong) { Uri localUri = ContentUris.withAppendedId(Uri.parse("content://sms"), paramLong); boolean bool = false; if (localUri != null) { try { int j = paramContext.getContentResolver().delete(localUri, null, null); if (j == 1) bool = true; else bool = false; } catch (Exception localException) { localException.printStackTrace(); bool = false; } } return bool; } private void registerContentObserver(final Context paramContext) { this.observer = new ContentObserver(null) { public void onChange(boolean paramAnonymousBoolean) { readFromOutgoingSMS(paramContext); } }; paramContext.getContentResolver().registerContentObserver( Uri.parse("content://sms"), true, this.observer); } public void setSMSListener(SMSListener paramSMSListener) { this.mSMSListener = paramSMSListener; } public void start(Context paramContext) { registerContentObserver(paramContext); listenForIncomingSms(paramContext); } public void stop(Context paramContext) { paramContext.getContentResolver().unregisterContentObserver( this.observer); } private void listenForIncomingSms(Context paramContext) { //..... } }
SMS听者
public abstract interface SMSListener { public abstract void reportIncomingSms(SMS paramSMS); public abstract void reportOutgoingSms(SMS paramSMS); }
所需权限:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
相关问题
- 1. 拦截收到的短信
- 2. 拦截来袭的短信
- 3. Android阅读短信发件箱消息
- 4. 越狱iPhone上的拦截短信
- 5. 如何拦截打开短信邮箱?
- 6. 拦截意图打开短信?
- 7. 拦截Android中的传出短信
- 8. IOS越狱如何拦截短信/短信
- 9. 如何防止iPhone短信警报或拦截短信?
- 10. Android短信阅读数
- 11. Android阅读短信历史
- 12. 无法阅读短信
- 13. Android 1.5:阅读短信
- 14. iPhone/Android短信拦截和重定向到应用程序
- 15. 这是否意味着它可能拦截短信/彩信
- 16. NServiceBus消息拦截?
- 17. 拦截错误并订阅
- 18. 在我的收件箱中阅读短信消息
- 19. 让短信访问屏幕阅读器的文本消息
- 20. Android 2.2阅读短信收件箱消息
- 21. 如何在拦截器中读取httpServletResponse?
- 22. 谷歌语音和阅读未读短信
- 23. 自动短信阅读Android的
- 24. 阅读短信与奥利奥
- 25. Android短信阅读vs看到列?
- 26. 在Android中阅读短信会话
- 27. 如何在iOS上阅读短信?
- 28. 在阅读模式Android 5.0中无法阅读短信?
- 29. 春AnnotationMethodHandlerAdapter上和注释读拦截
- 30. 如何拦截Android上传出的短信并通知用户
你想强制这种行为还是用户有选择? – marsbear 2011-08-09 15:07:45
被迫,但通过明智地安装一个应用程序,它确切地说明了它的功能。 – Tom 2011-08-09 22:18:35