Ven*_*kat 11 android ussd broadcastreceiver android-contacts
是否有可能处理预付费用户收到的通话费对话中显示的数据.我想在我的sqlite数据库中保存所有余额减少以及呼叫持续时间.
我们从已经很有名的博客文章中学习
首先,请查看Android源代码中的PhoneUtils类.[...]具体来说,查看第217行,正在编写一个名为"com.android.ussd.IExtendedNetworkService"的意图 .所以你需要做的是实现自己的服务来响应这个意图.该服务需要根据IExtendedNetworkService.aidl实现,它是Android框架的一部分.
从哪里开始?最好的是关注这个更着名的博客文章
首先,我们了解基础知识:
IExtendedNetworkService
接口的服务."com.android.ussd.IExtendedNetworkService"
,因此它将在应用程序清单中具有相应的意图过滤器.com.android.phone.PhoneUtils
将绑定到此服务.(如果您不知道服务的绑定,请参阅此处)让我们进入它.
首先,接收器,这是容易的部分.我们用这个内容创建一个名为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));
}
}
Run Code Online (Sandbox Code Playgroud)
现在,服务本身.我自己没有尝试过,但我已经阅读了这里的代码 来找到方法解释,我已经在评论中.我也编辑了一些东西.
据我所知,您将在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);
}}
Run Code Online (Sandbox Code Playgroud)
而最后一部分,清单.您必须注册该服务和广播接收者
<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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2140 次 |
最近记录: |