使用友盟对用户的意见反馈进行统计。
package com.dewmobile.zapya.receiver;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.widget.RemoteViews;
import com.dewmobile.library.pref.DmUserPreferences;
import com.dewmobile.zapya.R;
import com.dewmobile.zapya.activity.GetFeedBackList;
import com.dewmobile.zapya.activity.HomeActivity;
import com.dewmobile.zapya.activity.StartupActivity;
import com.dewmobile.zapya.application.Constants;
import com.dewmobile.zapya.fragment.FeedBackFragment;
import com.dewmobile.zapya.message.parse.Parse.MyIntent;
import com.dewmobile.zapya.notification.DmNotificationManager;
import com.umeng.fb.model.Conversation;
import com.umeng.fb.model.DevReply;
import com.umeng.fb.model.Reply;
public class FeedBackService extends Service {
private static final String TAG = "FeedBackService";
public static final int FEED_BACK_SERVICE_NOTIFICATION_ID = 0x001201;
private ScheduledThreadPoolExecutor executor;
private Conversation.SyncListener listener = new Conversation.SyncListener() {
@Override
public void onSendUserReply(List<Reply> replyList) {
if (replyList != null && replyList.size() > 0) onReplyChange(false);
}
private void onReplyChange(boolean isSentNotification) {
Log.i(TAG, "my feedback service run change");
Intent intent = new Intent("com.dewmobile.zapya.action.feedback");
sendBroadcast(intent);
if (isSentNotification && DmUserPreferences.getInstance().isFeedBackNotificationShow()) {
/**
* start feedbackfragment
*/
MyIntent myIntent = new MyIntent();
myIntent.intent = new Intent(getApplicationContext(), HomeActivity.class);
myIntent.intent.putExtra(HomeActivity.PAGE_INDEX_EXTAR,
FeedBackFragment.class.getSimpleName());
Intent startIntent = new Intent(getApplicationContext(), StartupActivity.class);
startIntent
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
if (myIntent != null) {
startIntent.putExtra(StartupActivity.EXTRA_PATH, StartupActivity.PAGE_MAIN);
if (myIntent.intent != null) {
startIntent.putExtra(StartupActivity.EXTRA_INTENT, myIntent.intent);
}
}
DmNotificationManager.Builder builder =
DmNotificationManager.getDefaultBuild(getApplicationContext(),
getResources().getText(R.string.feedback_notification_title),
getResources().getText(R.string.feedback_notification_title),
startIntent, FEED_BACK_SERVICE_NOTIFICATION_ID);
RemoteViews conterViews =
new RemoteViews(getPackageName(), R.layout.feedback_layout);
conterViews.setTextViewText(R.id.feed_back_tv,
getResources().getText(R.string.feedback_notification_title));
// conterViews.setTextColor(R.id.feed_back_tv, Color.RED);
builder.setContent(conterViews);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.icon21);
builder.setWhen(System.currentTimeMillis());
// builder.setNumber(0);
builder.setTicker(getResources().getText(R.string.feedback_notification_title));
builder.setEnableLight(true);
builder.setEnableSound(true);
builder.setEnableVibrate(true);
DmNotificationManager.getInstance().showNotify(builder);
}
}
@Override
public void onReceiveDevReply(List<DevReply> replyList) {
if (replyList != null && replyList.size() > 0) onReplyChange(true);
}
};
@Override
public void onCreate() {
super.onCreate();
executor = new ScheduledThreadPoolExecutor(1);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case Constants.Index.ONE:
GetFeedBackList.getInstance(getApplicationContext()).getDefaultConversation()
.sync(listener);
break;
}
super.handleMessage(msg);
}
};
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
executor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
handler.sendEmptyMessage(Constants.Index.ONE);
}
}, 1000, 30000, TimeUnit.MILLISECONDS);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
if (executor != null) {
executor.shutdown();
}
}
}
先使用一个service,在service中每隔一段时间更新,看是否有新的回复,如果有就发送广播
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.dewmobile.zapya.action.feedback")) {
lists.clear();
lists.addAll(GetFeedBackList.getInstance(getActivity()).getDefaultConversation()
.getReplyList());
replyListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
replyListView.setSelection(adapter.getCount());
}
}
};
接受广播的内部为具体对反馈做的一些数据处理