2014-09-26 111 views
2

我有一个间谍应用程序,我可以通过点击按钮隐藏菜单图标,但我无法通过电话拨号器, 取消隐藏一个Android应用程序,我有使用以下JAVA代码取消隐藏通过拨打号码

public class launchReceiver extends BroadcastReceiver { 
@Override 
    public void onReceive(Context context, Intent intent) { 
    String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
    String compare_num="#5555"; 
    if(number.equals(compare_num)) 
    {Intent myintent=new Intent(context,com.example.hide.MainActivity.class); 
     myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(myintent); 
     abortBroadcast();} }} 

清单代码

<receiver android:name=".launchReceiver" 
android:enabled="true" > 

<intent-filter android:priority="0"> 

<action android:name="android.intent.action.NEW_OUTGOING_CALL"/> 

</intent-filter> 

</receiver> 

回答

1

使用此代码:

public class launchReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    String phoneNumber = getResultData(); 
    if (phoneNumber == null) { 
     phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
    } 

     if(phoneNumber.equals("#5555")){ // DialedNumber checking. 
     setResultData(null); 

     // Start Application 
     Intent i=new Intent(context,MainActivity.class); 
     i.putExtra("extra_phone", phoneNumber); 
     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(i); 
     }  
} 

} 

并从清单中删除android:priority。

添加权限

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> 

清单中。

+0

在清单中,我声明收件人是正确的? user3343999 2014-09-26 10:50:28

+0

只是删除:android:priority =“0” – Sats 2014-09-26 11:37:39

+0

Thankx的帮助,但当我拨打号码#5555然后应用程序不幸closed.it是给予例外。 – user3343999 2014-09-26 12:11:34

1

重要:这是解决这一issue.And看到这点,努力

1)匹配的号码后取消隐藏在广播类应用程序中的取巧的方法。 2)然后使用Intent打开您的活动 3)当打开您的活动时,然后在onDestroy()方法中的活动中再次使用某个布尔值隐藏应用程序。