2015-06-30 53 views
0

我想在android上设置一个应用程序,当收到呼叫时计算点数,所以我想在收到呼叫时将呼叫动作+1点,并将点添加到应用程序中,发送到网站上的用户帐号, 那么我该如何做到这一点?收到呼叫时的呼叫动作android

+0

那么你尝试过什么?你有没有尝试过任何[Storage Options](http://developer.android.com/guide/topics/data/data-storage.html),比如Shared Preferences或SQLite Databases? – hoss

回答

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扩展广播接收器:

public class ReceiveIncomingCall extends BroadcastReceiver { 
    public void onReceive(Context context, Intent intent) { 
     //TODO call Webservice API to add one point 
    } 
}