USSD业务无法正常工作 [英] USSD service not working

查看:218
本文介绍了USSD业务无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一种默默驳回USSD响应的应用程​​序。 我用从 http://commandus.com/blog/?p=58 中的code与细微的变化。我创建了 IExtendedNetworkService.aidl 在包 com.android.internal.telephony USSDDumbExtendedNetworkService 包里面 com.commandus.ussd 。问题是,(即使重新启动手机后)运行该应用程序后,没有任何反应。 有人能指出我究竟做错了什么?我应该写任何额外的code为使其工作?

IExtendedNetworkService.aidl

 包com.android.internal.telephony;

/ **
*接口用于延长MMI / USSD的网络服务进行交互。
* /
接口IExtendedNetworkService {
 / **
 *进一步的过程中设置一个MMI / USSD命令ExtendedNetworkService。
 *当MMI命令放在从面板这应该叫。
 *参数号码拨打的MMI / USSD号码。
 * /
无效setMmiString(串号);

/ **
 *返回的用于提示的MMI / USSD正在运行特定字符串
 * /
CharSequence的getMmiRunningText();

/ **
 *获取应在弹出的对话框中显示特定的消息。
 * @参数文本原有的MMI / USSD消息框架响应
 * @返回特定的用户信息对应的文本。空表示没有弹出对话框需要显示。
 * /
CharSequence的getUserMessage(CharSequence的文字);

/ **
 *清除超时消息和pre-设置MMI / USSD指令
 *这应该当用户取消pre-拨打MMI命令来调用。
 * /
无效clearMmiString();
}
 

USSDDumbExtendedNetworkService

 包com.commandus.ussd;
    进口android.app.Service;
    进口android.content.BroadcastReceiver;
    进口android.content.Context;
    进口android.content.Intent;
    进口android.content.IntentFilter;
    进口android.net.Uri;
    进口android.os.IBinder;
    进口android.os.PatternMatcher;
    进口android.os.RemoteException;
    进口android.util.Log;

    进口com.android.internal.telephony.IExtendedNetworkService;

    / **
    *服务实现IExtendedNetworkService接口。
    * USSDDumbExtendedNetworkService服务必须有名称
    *com.android.ussd.IExtendedNetworkService的意图的声明中
    * Android清单文件,以便com.android.phone.PhoneUtils类绑定到这个
    *系统重新启动后的服务。请注意服务系统后装
    *重启!您的应用程序必须检查是系统重新启动。
    *
    * @see的Util#syslogHasLine(字符串,字符串,字符串,布尔)
    * /
    公共类USSDDumbExtendedNetworkService延伸服务{
    公共静态最终字符串变量=MobileServices;
    公共静态最后弦乐LOG_STAMP =* USSDTestExtendedNetworkService成功绑定*;
    公共静态最后弦乐URI_SCHEME =USSD;
    公共静态最后弦乐URI_AUTHORITY =g_el.net;
    公共静态最后弦乐URI_PATH =/;
    公共静态最后弦乐URI_PAR =回归;
    公共静态最后弦乐URI_PARON =上;
    公共静态最后弦乐URI_PAROFF =关;
    公共静态最后弦乐MAGIC_ON =:ON);
    公共静态最后弦乐MAGIC_OFF =:OFF(;
    公共静态最后弦乐MAGIC_RETVAL =:RETVAL;(;

    私有静态布尔mActive = FALSE;
    私有静态的CharSequence mRetVal = NULL;
    民营背景mContext = NULL;
    私人字符串msgUssdRunning =G测试...;

最后的BroadcastReceiver mReceiver =新的BroadcastReceiver(){
    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        如果(Intent.ACTION_INSERT.equals(intent.getAction())){
            mContext =背景;
            如果(mContext!= NULL){
                msgUssdRunning =USSD拦截器运行;
                mActive = TRUE;
                Log.d(TAG,激活);
            }
        }否则,如果(Intent.ACTION_DELETE.equals(intent.getAction())){
            mContext = NULL;
            mActive = FALSE;
            Log.d(TAG,取消);
        }
    }
};

私人最终IExtendedNetworkService.Stub mBinder =新IExtendedNetworkService.Stub(){

    @覆盖
    公共无效setMmiString(串号),将抛出RemoteException {
        Log.d(TAG,setMmiString:+号);
    }

    @覆盖
    公众的CharSequence getMmiRunningText()将抛出RemoteException {
        Log.d(TAG,getMmiRunningText:+ msgUssdRunning);
        返回msgUssdRunning;
    }

    @覆盖
    公共CharSequence的getUserMessage(CharSequence的文字)
            将抛出RemoteException {
        如果(MAGIC_ON.contentEquals(文本)){
            mActive = TRUE;
            Log.d(TAG,控制:ON);
            返回文本;
        } 其他 {
            如果(MAGIC_OFF.contentEquals(文本)){
                mActive = FALSE;
                Log.d(TAG,控制:OFF);
                返回文本;
            } 其他 {
                如果(MAGIC_RETVAL.contentEquals(文本)){
                    mActive = FALSE;
                    Log.d(TAG,控制:回归);
                    返回mRetVal;
                }
            }
        }

        如果(!mActive){
            Log.d(TAG,getUserMessage停用:+文字);
            //返回空; //使用此为了消除屏幕上的输出。
            返回文本;
        }
        字符串s = text.toString();
        //将S的!
        开放的URI =新Uri.Builder().scheme(URI_SCHEME).authority(URI_AUTHORITY).path(URI_PATH).appendQueryParameter(URI_PAR,text.toString()).build();
        sendBroadcast(新意图(Intent.ACTION_GET_CONTENT,URI));
        mActive = FALSE;
        mRetVal =文本;
        Log.d(TAG,getUserMessage:+文字+=+ S);
        返回null;
    }

    @覆盖
    公共无效clearMmiString()将抛出RemoteException {
        Log.d(TAG,clearMmiString);
    }
};

/ **
 *把邮票贴在系统日志时PhoneUtils绑定后的服务
 * Android已经重新启动。应用程序必须调用
 * {@link的Util#syslogHasLine(字符串,字符串,字符串,布尔)}是检查
 *手机重新启动或没有。如果没有重新启动手机应用程序不绑定汤姆
 *此服务!
 * /
@覆盖
公众的IBinder onBind(意向意图){
    IntentFilter的过滤器=新的IntentFilter();
    filter.addAction(Intent.ACTION_INSERT);
    filter.addAction(Intent.ACTION_DELETE);
    filter.addDataScheme(URI_SCHEME);
    filter.addDataAuthority(URI_AUTHORITY,NULL);
    filter.addDataPath(URI_PATH,PatternMatcher.PATTERN_LITERAL);
    registerReceiver(mReceiver,过滤器);
    //不要本地化!
    Log.i(TAG,LOG_STAMP);

    返回mBinder;
}

公众的IBinder asBinder(){
    Log.d(TAG,asBinder);
    返回mBinder;
}

@覆盖
公共布尔onUnbind(意向意图){
    unregisterReceiver(mReceiver);
    返回super.onUnbind(意向);
}

   }
 

清单文件

 <服务机器人:名称=com.commandus.ussd.USSDDumbExtendedNetworkService>
        <意向滤光器>
            <作用机器人:名称=com.android.ussd.IExtendedNetworkService/>
                <类机器人:名称=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
 < /服务>
 

解决方案

你有没有在你的清单文件中声明的广播接收器?

添加您的清单里面的:

 <接收器的Andr​​oid版本:NAME =com.xxx.receivers.BootReceiver>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
            &所述; /意图滤光器>
        < /接收器>

<服务机器人:名称=your.package.ExtendedNetworkService/>
 

在BootReceiver.java:

 公共无效的onReceive(上下文的背景下,意图意图){

        context.startService(新意图(背景下,ExtendedNetworkService.class));
}
 

在ExtendedNetworkService.java:

 公共类ExtendedNetworkService延伸服务{

    IExtendedNetworkService.Stub粘合剂=新IExtendedNetworkService.Stub(){

        公共无效setMmiString(串号),将抛出RemoteException {}
        公众的CharSequence getMmiRunningText()将抛出RemoteException {

            返回null;
        }
        公共CharSequence的getUserMessage(CharSequence的文字)
                将抛出RemoteException {

            Log.d(Constants.TAG,消息:+文字);
            Log.d(Constants.TAG,getMmiRunningTest():+ getMmiRunningText());
                返回null;
        }
        公共无效clearMmiString()将抛出RemoteException {
        }

    };

        返回false;
    }

    公共无效的onCreate(){

        Log.d(Constants.TAG,ExtendedNetworkService开始..);

        super.onCreate();
    }

公众的IBinder onBind(意向为arg0){

        Log.d(Constants.TAG,ExtendedNetworkService得到了绑定......);

        返回粘合剂;

    }

}
 

I'm trying to develop an application which silently dismiss the USSD responses. I've used the code from http://commandus.com/blog/?p=58 with minor changes. I've created the IExtendedNetworkService.aidl in the package com.android.internal.telephony and USSDDumbExtendedNetworkService inside the package com.commandus.ussd. The problem is, nothing happens after running the application (even after restarting the phone). Can someone point out what am I doing wrong? Should I write any additional code for making it work?

IExtendedNetworkService.aidl

package com.android.internal.telephony;

/**
*  Interface used to interact with extended MMI/USSD network service.
*/
interface IExtendedNetworkService {
 /**
 * Set a MMI/USSD command to ExtendedNetworkService for further process.
 * This should be called when a MMI command is placed from panel.
 * @param number the dialed MMI/USSD number.
 */
void setMmiString(String number);

/**
 * return the specific string which is used to prompt MMI/USSD is running
 */
CharSequence getMmiRunningText();

/**
 * Get specific message which should be displayed on pop-up dialog.
 * @param text original MMI/USSD message response from framework
 * @return specific user message correspond to text. null stands for no pop-up dialog need to show.
 */
CharSequence getUserMessage(CharSequence text);

/**
 * Clear timeout message and pre-set MMI/USSD command
 * This should be called when user cancel a pre-dialed MMI command.
 */
void clearMmiString();
}

USSDDumbExtendedNetworkService

    package com.commandus.ussd;
    import android.app.Service;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.net.Uri;
    import android.os.IBinder;
    import android.os.PatternMatcher;
    import android.os.RemoteException;
    import android.util.Log;

    import com.android.internal.telephony.IExtendedNetworkService;

    /**
    * Service implements IExtendedNetworkService interface.
    * USSDDumbExtendedNetworkService Service must have name
    * "com.android.ussd.IExtendedNetworkService" of the intent declared in the
    * Android manifest file so com.android.phone.PhoneUtils class bind to this
    * service after system rebooted. Please note service is loaded after system
    * reboot! Your application must check is system rebooted.
    * 
    * @see Util#syslogHasLine(String, String, String, boolean)
    */
    public class USSDDumbExtendedNetworkService extends Service {
    public static final String TAG = "MobileServices";
    public static final String LOG_STAMP = "*USSDTestExtendedNetworkService bind successfully*";
    public static final String URI_SCHEME = "ussd";
    public static final String URI_AUTHORITY = "g_el.net";
    public static final String URI_PATH = "/";
    public static final String URI_PAR = "return";
    public static final String URI_PARON = "on";
    public static final String URI_PAROFF = "off";
    public static final String MAGIC_ON = ":ON;)";
    public static final String MAGIC_OFF = ":OFF;(";
    public static final String MAGIC_RETVAL = ":RETVAL;(";

    private static boolean mActive = false;
    private static CharSequence mRetVal = null;
    private Context mContext = null;
    private String msgUssdRunning = "G Testing...";

final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_INSERT.equals(intent.getAction())) {
            mContext = context;
            if (mContext != null) {
                msgUssdRunning = "ussd blocker Running";
                mActive = true;
                Log.d(TAG, "activate");
            }
        } else if (Intent.ACTION_DELETE.equals(intent.getAction())) {
            mContext = null;
            mActive = false;
            Log.d(TAG, "deactivate");
        }
    }
};

private final IExtendedNetworkService.Stub mBinder = new IExtendedNetworkService.Stub() {

    @Override
    public void setMmiString(String number) throws RemoteException {
        Log.d(TAG, "setMmiString: " + number);
    }

    @Override
    public CharSequence getMmiRunningText() throws RemoteException {
        Log.d(TAG, "getMmiRunningText: " + msgUssdRunning);
        return msgUssdRunning;
    }

    @Override
    public CharSequence getUserMessage(CharSequence text)
            throws RemoteException {
        if (MAGIC_ON.contentEquals(text)) {
            mActive = true;
            Log.d(TAG, "control: ON");
            return text;
        } else {
            if (MAGIC_OFF.contentEquals(text)) {
                mActive = false;
                Log.d(TAG, "control: OFF");
                return text;
            } else {
                if (MAGIC_RETVAL.contentEquals(text)) {
                    mActive = false;
                    Log.d(TAG, "control: return");
                    return mRetVal;
                }
            }
        }

        if (!mActive) {
            Log.d(TAG, "getUserMessage deactivated: " + text);
            //return null;//Use this in order to cancel the output on the screen.
            return text;
        }
        String s = text.toString();
        // store s to the !
        Uri uri = new Uri.Builder().scheme(URI_SCHEME).authority(URI_AUTHORITY).path(URI_PATH).appendQueryParameter(URI_PAR,text.toString()).build();
        sendBroadcast(new Intent(Intent.ACTION_GET_CONTENT, uri));
        mActive = false;
        mRetVal = text;
        Log.d(TAG, "getUserMessage: " + text + "=" + s);
        return null;
    }

    @Override
    public void clearMmiString() throws RemoteException {
        Log.d(TAG, "clearMmiString");
    }
};

/**
 * Put stamp to the system log when PhoneUtils bind to the service after
 * Android has rebooted. Application must call
 * {@link Util#syslogHasLine(String, String, String, boolean)} to check is
 * phone rebooted or no. Without reboot phone application does not bind tom
 * this service!
 */
@Override
public IBinder onBind(Intent intent) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_INSERT);
    filter.addAction(Intent.ACTION_DELETE);
    filter.addDataScheme(URI_SCHEME);
    filter.addDataAuthority(URI_AUTHORITY, null);
    filter.addDataPath(URI_PATH, PatternMatcher.PATTERN_LITERAL);
    registerReceiver(mReceiver, filter);
    // Do not localize!
    Log.i(TAG, LOG_STAMP);

    return mBinder;
}

public IBinder asBinder() {
    Log.d(TAG, "asBinder");
    return mBinder;
}

@Override
public boolean onUnbind(Intent intent) {
    unregisterReceiver(mReceiver);
    return super.onUnbind(intent);
}

   }

Manifest file

<service android:name="com.commandus.ussd.USSDDumbExtendedNetworkService">
        <intent-filter >
            <action android:name="com.android.ussd.IExtendedNetworkService" />
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
 </service>

解决方案

Have you declared your broadcast receiver in your manifest file?

add inside your manifest:

<receiver android:name="com.xxx.receivers.BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

<service android:name="your.package.ExtendedNetworkService" />

in BootReceiver.java :

    public void onReceive(Context context, Intent intent) {

        context.startService(new Intent(context,ExtendedNetworkService.class));
}

in ExtendedNetworkService.java :

public class ExtendedNetworkService extends Service {

    IExtendedNetworkService.Stub binder = new IExtendedNetworkService.Stub() {

        public void setMmiString(String number) throws RemoteException {}
        public CharSequence getMmiRunningText() throws RemoteException {

            return null;
        }
        public CharSequence getUserMessage(CharSequence text)
                throws RemoteException {

            Log.d(Constants.TAG, "Message : " + text);
            Log.d(Constants.TAG, "getMmiRunningTest() : " + getMmiRunningText());
                return null;
        }
        public void clearMmiString() throws RemoteException {
        }

    };

        return false;
    }

    public void onCreate() {

        Log.d(Constants.TAG, "ExtendedNetworkService Started..");

        super.onCreate();
    }

public IBinder onBind(Intent arg0) {

        Log.d(Constants.TAG, "ExtendedNetworkService got binded...");

        return binder;

    }

}

这篇关于USSD业务无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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