是否有可能读取对话通话费用的历史结束了prepaid电话后提出?有可能、费用、电话、结束了

2023-09-04 09:35:17 作者:孤家寡人う

有没有处理由prepaid用户接收到通话费用对话中显示的数据的可能性。我要保存所有的余额减少的同时在我的SQLite数据库通话时间。

Is there a possibility of handling the data displayed on call cost dialogue received by prepaid user. I want to save all the balance reduction for along with call duration in my sqlite db.

推荐答案

当我们从已经成名的博客文章

作为开始,看看PhoneUtils类的Andr​​oid源$ C ​​$ C。   [...]   具体而言,在看线217,意图与名称   com.android.ussd.IExtendedNetworkService正在组成。 等什么   你需要做的就是实现自己的服务,响应该   意图。的服务需要根据实施   IExtendedNetworkService.aidl这是Android架构的一个组成部分。

As a start, look at the PhoneUtils class in the Android source code. [...] Specifically, looking at line 217, an intent with the name "com.android.ussd.IExtendedNetworkService" is being composed. So what you need to do is implement your own service that responds to that intent. The service needs to be implemented according to the IExtendedNetworkService.aidl which is a part of the Android framework.

从哪里开始?最好的是遵循这一更加出名博客帖子

where to start at? the best is to follow this even more famous blog post

首先,我们了解的基础知识:

First of all, we understand the basics:

我们需要一种服务,它实现 IExtendedNetworkService 接口。 在该服务会意识到的意图com.android.ussd.IExtendedNetworkService,所以它必须在应用程序清单对应的意图过滤器。 我们知道的是, com.android.phone.PhoneUtils 将绑定到该服务。 (如果你不知道什么是绑定服务,请参阅这里) 在绑定我们返回的粘合剂,它contanins的函数PhoneUtils居然会叫 在该服务已被运行,因此我们将它开始系统重启时。为此,我们需要一个广播接收机。 (如果你不知道这是什么,你要明白这一切的美好,参考这里 ) We need a service that implements IExtendedNetworkService interface. The service will be aware of the intent "com.android.ussd.IExtendedNetworkService", so it will have the correspondent intent filter in the app manifest. What we know is that com.android.phone.PhoneUtils will bind to this service. (If you dont know what binding a service is, refer to here) on Bind we return a binder, which contanins the functions that PhoneUtils will actually call The service has to be be running, so we will have it started when the system reboot. For that we need a broadcast receiver. (If you don't know what is this, and you want to understand all this better, refer to here)

Let`s进入它。

首先,接收器,这是比较容易的部分。我们做了一个名为BootReceiver.java与此内容的文件。

First, the receiver, this is the easy part. We make a file called BootReceiver.java with this contents.

package com.android.ussdcodes;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.d("USSDService", context.getString(R.string.service_started));
        context.startService(new Intent(context,USSDDumbExtendedNetworkService.class));
    }

}

现在,服务本身。我还没有尝试过自己,但我已经阅读了code here找到方法的说明,我已经把意见。此外,我编辑的一些东西。

Now, the service itself. I havent tried it myself, but i have read the code here to find the methods explanation, that i've put in comments. Also i edited some stuff.

据我了解,您将收到的实际文本中getUserMessage,有你分析文本,并返回你想要的是在弹出。如果你不想弹出,返回null。因此,它也有,你应该做任何其他的东西与文本。

As far as i understand, you will receive the actual text in getUserMessage, there you parse the text, and return what you want to be in the popup. If you dont want popup, return null. So, it is also there where you should do any other stuff with that text.

public class USSDDumbExtendedNetworkService extends Service {

public static final String TAG = "ExtNetService";
public static CharSequence mRetVal = null;
public static boolean mActive = true;
private boolean change = false;
private String msgUssdRunning = null;

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


    //Set a MMI/USSD command to ExtendedNetworkService for further process. This should be called when a MMI command is placed from panel.
    //we don't need it in this case
    @Override
    public void setMmiString(String number) throws RemoteException {

    }



    //return the specific string which is used to prompt MMI/USSD is running

    @Override
    public CharSequence getMmiRunningText() throws RemoteException {
        return msgUssdRunning;
    }

    //Get specific message which should be displayed on pop-up dialog.
   Parameters:
   text original MMI/USSD message response from framework
   Returns:
   specific user message correspond to text. null stands for no pop-up dialog need to show.
    @Override
    public CharSequence getUserMessage(CharSequence text)
            throws RemoteException {
         return text;
    }
   //Clear pre-set MMI/USSD command. This should be called when user cancel a pre-dialed MMI    command.
    //we don't need it in this case
    @Override
    public void clearMmiString() throws RemoteException {
    }
};

@Override
public IBinder onBind(Intent intent) {
    msgUssdRunning = "Some text to show";

    return mBinder; 
}

public IBinder asBinder() {
    return mBinder;
}

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

和最后一部分,清单。你必须注册服务,以及BroadcastReceiver的

And the last part, the manifest. You have to register the service, and the broadcastreceiver

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

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