友盟的一些使用

使用友盟对用户的意见反馈进行统计。

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());
            }
        }
    };

接受广播的内部为具体对反馈做的一些数据处理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值