是否有可能处理预付费用户收到的通话费对话中显示的数据。我希望在我的sqlite数据库中保存所有余额减少和呼叫持续时间。
答案 0 :(得分:5)
我们从已经很有名的blog post
中学习首先,请查看Android源代码中的PhoneUtils类。 [...] 具体来说,查看第217行,具有名称的意图 正在撰写“com.android.ussd.IExtendedNetworkService”。 那是什么 你需要做的是实现你自己的服务,以响应这一点 意图即可。该服务需要按照实施 IExtendedNetworkService.aidl是Android框架的一部分。
从哪里开始?最好的是遵循这个更有名的blog post
首先,我们了解基础知识:
IExtendedNetworkService
接口的服务。"com.android.ussd.IExtendedNetworkService"
,因此它将在应用清单中包含相应的意图过滤器。com.android.phone.PhoneUtils
将绑定到此服务。 (如果您不知道服务绑定的内容,请参阅here)让我们进入它。
首先,接收器,这是容易的部分。我们用这个内容创建一个名为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));
}
}
现在,服务本身。我自己没有尝试过,但是我已经阅读了代码here以找到方法解释,我已将其放入评论中。我也编辑了一些东西。
据我所知,您将在getUserMessage中收到实际文本,在那里解析文本,然后返回弹出窗口中的内容。如果你不想弹出,请返回null。所以,它也应该在那里你应该用该文本做任何其他的东西。
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>