如果声明:请先读“ else”

问题描述 投票:0回答:1

嗨,我需要有关陈述的帮助,在检查情况之前,它总是跳转到其他地方!我的代码:

@Override
public void onReceive(Context p1, Intent p2)
{
    if ("android.intent.action.BOOT_COMPLETED".equals(p2.getAction())) {
        Toast.makeText(p1, "Device is ON from Recever",Toast.LENGTH_LONG).show();
    Intent starServiceIntent = new Intent(p1,MyService.class);
   p1 .startService(starServiceIntent);

    }   @Override
public void onReceive(Context p1, Intent p2)
{
    if ("android.intent.action.BOOT_COMPLETED".equals(p2.getAction())) {
        Toast.makeText(p1, "Device is ON from Recever",Toast.LENGTH_LONG).show();
    Intent starServiceIntent = new Intent(p1,MyService.class);
   p1 .startService(starServiceIntent);

    } if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){

        SharedPreferences prefs = p1.getSharedPreferences("myPrefss", Context.MODE_PRIVATE);
        if(!prefs.contains(incomingNumber)){
            Toast.makeText(p1,"True",Toast.LENGTH_SHORT).show();
            DateFormat timeFormat = new SimpleDateFormat("dd-MM-yy HH:mm");
            timeFormat.setTimeZone(TimeZone.getTimeZone("Asia/Jerusalem"));
            String curTime = timeFormat.format(new Date());


            SharedPreferences.Editor editor = prefs.edit();
            editor.putString(incomingNumber, curTime);
            editor.commit();
            sendSMS(incomingNumber,p1);

        }else{
            getStored(p1,incomingNumber);
            Toast.makeText(p1,"False",Toast.LENGTH_SHORT).show();
        }


        } 

//先给我假,然后给真,即使满足条件

android service broadcastreceiver
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.