1

我的要求是在输入密码时启动隐藏的应用程序。

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

<?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>

当我运行项目时,出现以下异常: connection problem invalid mmi code android

谁能帮忙

问候, 巴拉

4

2 回答 2

0

当我们得到拨号号码时,我使用了相同的代码,它是一个不包含 *、# 的号码。在清单文件中,我们必须像这样声明接收者

<receiver android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>

并将权限写为<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

只需查看以下编辑后的代码:

使用 BroadcastReceiver 如下:

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);
        }    
    }
}

不要忘记在清单中注册此接收器

<receiver android:name="MyOutgoingCallHandler">
    <intent-filter >
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter>
</receiver>

另外,包括权限:

现在,如果您忽略接收器中的号码,您将在 MainActivity 中获得拨打的号码,

String phone=getIntent().getStringExtra("extra_phone");
    if(!phone.equals(null)){
        Toast.makeText(getBaseContext(), phone, Toast.LENGTH_LONG).show();
    }

如果您想启动应用程序作为对幻数的调用,使用 BroadcastReceivers 进行拨出电话非常简单,您可以从 Right Number 应用程序获得解决方案

于 2015-01-28T09:13:26.247 回答
0

异常:连接问题无效的mmi代码android

要检测拨出电话事件,您应该NEW_OUTGOING_CALL在以下位置使用 Action注册广播AndroidManifest.xml

<receiver android:name=".MainActivity">
   <intent-filter>
     <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

并添加PROCESS_OUTGOING_CALLS权限:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
于 2015-01-28T09:11:19.547 回答