预付费用户收到的通话费用对话框所显示的数据是否可以处理?我想将所有余额减少和通话持续时间保存在我的sqlite数据库中。
预付费用户收到的通话费用对话框所显示的数据是否可以处理?我想将所有余额减少和通话持续时间保存在我的sqlite数据库中。
从已经著名的博客文章中我们了解到:
首先,看一下Android源代码中PhoneUtils类。 [...] 特别是,查看第217行,一个名为“com.android.ussd.IExtendedNetworkService”的意图正在被组成。所以你需要做的就是实现自己的服务来响应那个意图。该服务需要按照Android框架的IExtendedNetworkService.aidl进行实现。
从何处着手呢?最好的方法是遵循这篇更著名的博客文章
首先,我们了解基础知识:
让我们开始吧。
首先是接收器,这部分很容易。我们创建一个名为BootReceiver.java的文件,文件内容如下:
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));
}
}
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);
}}
最后一部分,清单文件。您必须注册服务和广播接收器。
<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>