使用秘密code通过拨号键盘android的启动活动 [英] Launch Activity in android via Dialpad using Secret Code

查看:324
本文介绍了使用秘密code通过拨号键盘android的启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想通过推出活动秘密code

I just want to launch activity via Secret Code .

虽然,有可用于这个问题的许多解决方案,但他们没有为我工作。它看起来像广播接收器就是不听。

Although , there are many solutions available for this problem but none of them worked for me. It seems like BroadcastReceiver is not listening .

我使用Mi4i MIUI 7.

I am using Mi4i MIUI 7.

下面是我的code。请帮助!

Here's my code. Please Help!!

MainActivity.java

package com.example.jatin.myapplication2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
    }

}

我甚至尝试下面的评论code,但没有奏效。

I have even tried the below commented code , but that didn't work.

MySecret codeReceiver.java

package com.example.jatin.myapplication2;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

 /**
 * Created by Jatin on 05-Aug-16.
 */
 public class MySecretCodeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
        String uri  =  intent.getDataString();
        String sep[] = uri.split("://");
        if (sep[1].equalsIgnoreCase("1234"))
        {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.example.jatin.myapplication2.MainActivity");
            context.startActivity(launchIntent);

        }
        else if (sep[1].equalsIgnoreCase("5678")) {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("net.one97.paytm");
            context.startActivity(launchIntent);
        }

//            Intent i = new Intent(context, MainActivity.class);
//            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            setResultData(null);
//            context.startActivity(i);

       }
    }

}

我也试图把机器人:主机=1234中的表现,仍然没有得到想要的结果。

I have also tried putting android:host="1234" in manifest ,still not getting desired results

的Andr​​oidManifest.xml

  <?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
<receiver android:name="receivers.MySecretCodeReceiver"
    android:enabled="true"
    android:exported="true"
    android:permission="android.permission.PROCESS_OUTGOING_CALLS">
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE"  />
        <data android:scheme="android_secret_code" />
    </intent-filter>
</receiver>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"

    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

推荐答案

明白了 ...

我们需要注册我们的 MySecret codeReceiver 为&LT; 接收>在&lt之内;中的应用>元素< STRONG>的Andr​​oidManifest.xml 文件。

We have to register our MySecretCodeReceiver as a <receiver> within the <application> element in the AndroidManifest.xml file.

和,它的完成。 :)

这篇关于使用秘密code通过拨号键盘android的启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆