我想在 android 上创建一个应用程序,在收到来电时计算点数,所以我想在收到来电时调用+1点动作并在应用内添加积分并发送到网站上的用户帐户, 那我该怎么办呢?
答案 0 :(得分:0)
使用BroadcastReceiver,AndroidManifest中的代码应为:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidexample.broadcastreceiver"
android:versionCode="1"
android:versionName="1.0" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.androidexample.broadcastreceiver.BroadcastPhoneStates"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ReceiveIncomingCall">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
</manifest>
创建了一个类ReceiveIncomingCall extends BroadcastReceiver:
public class ReceiveIncomingCall extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
//TODO call Webservice API to add one point
}
}