【发布时间】:2011-10-14 10:45:06
【问题描述】:
我创建了一个安全应用程序,就像 Mcafee wave secure 一样。
我的应用程序正在侦听 SMS 命令并在命令匹配时执行一些操作,因此我创建了一个带有另一个服务的表单来侦听 SMS。
这是主要的形式:
public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
ArrayList<String> messageList;
ArrayAdapter< String> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//untuk mendisable notification area
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
MainButtonAbout=(Button) findViewById(R.id.MainbuttonAbout);
MainButtonHelp=(Button) findViewById(R.id.MainbuttonHelp);
MainButtonWizard=(Button) findViewById(R.id.MainbuttonWizard);
MainButtonOption=(Button) findViewById(R.id.MainbuttonOption);
MainCheckBoxActive=(CheckBox)findViewById(R.id.MaincheckBoxActive);
MainButtonAbout.setOnClickListener(this);
MainButtonHelp.setOnClickListener(this);
MainButtonWizard.setOnClickListener(this);
MainButtonOption.setOnClickListener(this);
startService(new Intent(MainForm.this, ListenSMSservice.class));
MainCheckBoxActive.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (buttonView.isChecked())
{
Toast.makeText(MainForm.this, "Your Device is Protected Now!!", 1).show();
startService(new Intent(MainForm.this, ListenSMSservice.class));
}
else
{
Toast.makeText(MainForm.this, "Your Device is not Protected Now!!", 1).show();
stopService(new Intent(MainForm.this, ListenSMSservice.class));
}
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.MainbuttonAbout:
Intent GoToAbout= new Intent(this,AboutForm.class);
startActivity(GoToAbout);
break;
case R.id.MainbuttonHelp:
Intent GoToHelp= new Intent(this,HelpForm.class);
startActivity(GoToHelp);
break;
case R.id.MainbuttonWizard:
Intent GoToWizard1= new Intent(this,WizardForm1.class);
startActivity(GoToWizard1);
break;
case R.id.MainbuttonOption:
Intent GoToOption= new Intent(this,OptionForm.class);
startActivity(GoToOption);
break;
default:
break;
}
}
这是服务表单:
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
}
/*@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
ListenSMS();
}*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
ListenSMS();
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
}
private void ListenSMS() {
// TODO Auto-generated method stub
messageList = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, messageList);
//Toast.makeText(this, "Masuk bagian sini sudah", 1).show();
IntentFilter filter = new IntentFilter(SMS_RECEIVED);
registerReceiver(receiver_SMS, filter);
}
BroadcastReceiver receiver_SMS = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(SMS_RECEIVED))
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
for (SmsMessage message : messages)
{
Toast.makeText(ListenSMSservice.this, "isi pesan >> "+message.getDisplayMessageBody(), Toast.LENGTH_LONG).show();
receivedMessage(message.getDisplayOriginatingAddress());
if (message.getDisplayMessageBody().toString().equalsIgnoreCase("aaaa"))
{
Toast.makeText(ListenSMSservice.this, "messegenya aaaa", 1).show();
}
}
}
}
}
};
private void receivedMessage(String message)
{
messageList.add(message);
adapter.notifyDataSetChanged();
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
}
很遗憾,我的服务可以被高级任务杀手停止,所以我无法收听短信命令。
我正在使用start_sticky 选项,但它对我不起作用。
有谁知道如何处理这个问题,所以即使任务杀手被用来杀死我的应用程序,我也可以收听 SMS(自动启动服务)?
【问题讨论】:
-
如果用户通过 3rd 方工具或设置菜单强制停止您的应用程序,那么他们希望将其停止。
-
是的,当然.. 但我做了一个安全应用程序。如果设备被盗或丢失,我的应用程序应该可以工作。我的应用程序可以锁定安卓设备,这样小偷就无法访问手机。如果我的服务可以停止,如何防止丢失的手机被小偷访问?有什么解决办法??谢谢..
-
您声称正在提供“安全服务”。您可能正在创建恶意软件,因为恶意软件可能具有您描述的功能。 Android 可以保护用户免受恶意软件的侵害,这意味着它可以保护用户免受您的“安全服务”的侵害。有更好的解决方案可以保护用户免受属于(或可能属于)操作系统一部分的手机丢失/被盗/扣押(例如,整个磁盘加密)。
-
这是我的最后一个项目。我创建了一个像 mcafee wave secure 这样的应用程序。如果你说我创建了一个恶意软件,那么 mcafee wave secure 怎么样??
标签: java android android-widget android-ndk android-manifest