2013-01-10 77 views
-1

我在java中有一個Android應用程序,並且我不希望我的應用程序在我收到來電時關閉。如何阻止來電關閉我的程序?

有誰知道一種方法來阻止來電關閉在java中的應用程序?

+0

您以這樣的方式提出了您的問題,這將吸引負面關注。如果你希望我編輯你的問題看起來更有吸引力,比在評論中告訴我,我會這樣做 –

+0

我會很感激 – scepeda

+0

你使用什麼語言? –

回答

0

是的,你可以阻止來電。使用此代碼

String phonestate = bundle.getString(TelephonyManager.EXTRA_STATE); 

try 
{ 
    if (TelephonyManager.EXTRA_STATE_RINGING.equalsIgnoreCase(phonestate)) 
    { 
     try 
     { 
      TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
      Class c = Class.forName(tm.getClass().getName()); 
      Method m = c.getDeclaredMethod("getITelephony"); 
      m.setAccessible(true); 
      telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 

     if (prefStatus != null) 
     { 
      if (count == 1) 
      { 
       telephonyService.endCall(); 
       String prefLoginemail = myloginpref.getString("emailid", null); 
       System.out.println(printdata + " prefLoginemail :: "+ prefLoginemail); 

       Global.mNotificationManager = (NotificationManager) mxcontext.getSystemService(Context.NOTIFICATION_SERVICE); 
       notifyDetails = new Notification(com.CellPhoneTerror.R.drawable.icon1,"CellPhoneTerror!", System.currentTimeMillis()); 
       myIntent = PendingIntent.getActivity(mxcontext, 0, new Intent(mxcontext, clsHomePage.class), 0); 

       notifyDetails.setLatestEventInfo(mxcontext,"You Got a Call from Blocked Number.", "",myIntent); 
       notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; 
       Global.mNotificationManager.notify(Global.SIMPLE_NOTFICATION_ID,notifyDetails); 

      } 
     } 
    } 
    if (prefIncomingBlock.equals("true")) 
    { 
     if (TelephonyManager.EXTRA_STATE_IDLE.equalsIgnoreCase(phonestate)) 
     { 
      if (count == 0) 
      { 
       System.out.println("if Cellphoneterror:"+ Global.clsIncomingNum); 
       Intent block = new Intent(context, dialogbox1.class); 
       block.setFlags(intent.FLAG_ACTIVITY_NEW_TASK); 
       context.startActivity(block); 
      } 
     } 
    } 
} 
catch (Exception e) 
{ 
    e.printStackTrace(); 
} 
+0

它似乎從android 2.3以來不起作用 – scepeda