启动隐藏的应用程序时,秘密code拨打 [英] launch hidden app when secret code is dialed
问题描述
我的要求是要推出一个隐藏的应用程序时,一个秘密code为dailed。
my requirement is to launch an hidden app when a secret code is dailed.
MainActivity.java
MainActivity.java
public class MainActivity extends
BroadcastReceiver {
String dialed_number;
@Override
public void onReceive(Context context, Intent intent)
{
dialed_number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if(dialed_number.equals("*0*1235#"))
{
Intent appIntent = new Intent(context, MainActivity.class);
appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(appIntent);
setResultData(null);
}
}
}
AndroidManifest.xml中
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tuto.bala.helloworld" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name=".MainActivity">
</receiver>
</application>
</manifest>
当我运行该项目,我得到下面的异常:
连接问题无效MMI code的android
When i run the project I get the following exception: connection problem invalid mmi code android
任何人都可以请帮助
问候,
巴拉
推荐答案
我用同样的code它的工作时,我们得到拨号号码被一些不包括*,#。在清单文件我们必须声明接收器像这样
I have used same code it's working when we are given dial number is a number not to include *,#. and in Manifest file we have to declare the receiver like this
<receiver android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
和写入权限为&LT;使用许可权的android:NAME =android.permission.PROCESS_OUTGOING_CALLS/&GT;
刚看到下面的编辑code:
Just see the below edited code:
如下使用广播接收器:
public class MyOutgoingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Extract phone number reformatted by previous receivers
String phoneNumber = getResultData();
if (phoneNumber == null) {
// No reformatted number, use the original
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
if(phoneNumber.equals("1234")){ // DialedNumber checking.
// My app will bring up, so cancel the broadcast
setResultData(null);
// Start my app
Intent i=new Intent(context,MainActivity.class);
i.putExtra("extra_phone", phoneNumber);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
不要忘了在你的清单中注册该接收器
Don't forget to register this receiver in your manifest
<receiver android:name="MyOutgoingCallHandler">
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
此外,包括权限:
Also, include the permission:
现在,如果你忽略了一些接收器检查,你会得到你拨打里面MainActivity号,
Now, if you are ignoring the number checking in receiver, you'll get dialed number inside your MainActivity,
String phone=getIntent().getStringExtra("extra_phone");
if(!phone.equals(null)){
Toast.makeText(getBaseContext(), phone, Toast.LENGTH_LONG).show();
}
如果要启动的应用程序的调用神奇的数字,它的使用呼出BroadcastReceivers很简单,你可以从右键数应用解决方案获得
If you want to launch app as call to magic number, it's quite simple using BroadcastReceivers for outgoing call, you can get solution from Right Number app
这篇关于启动隐藏的应用程序时,秘密code拨打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!