• 大小: 2.09M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2020-12-24
  • 语言: Java
  • 标签: Android  

资源简介

android 统计

核心源码:

package com.umeng.example.analytics;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;
import com.umeng.analytics.social.UMPlatformData;
import com.umeng.analytics.social.UMPlatformData.GENDER;
import com.umeng.analytics.social.UMPlatformData.UMedia;
import com.umeng.example.R;
import com.umeng.ui.BaseSinglePaneActivity;

public class AnalyticsHome extends BaseSinglePaneActivity {	
	private Context mContext;
	private final  String mPageName = "AnalyticsHome";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		MobclickAgent.setDebugMode(true);
//      SDK在统计Fragment时,需要关闭Activity自带的页面统计,
//		然后在每个页面中重新集成页面统计的代码(包括调用了 onResume 和 onPause 的Activity)。
		MobclickAgent.openActivityDurationTrack(false);
//		设置地理位置信息setLocation(double lat,double lng)
//		AnalyticsConfig.setLocation(20, 100);
//		MobclickAgent.setSessionContinueMillis(2000);		

		MobclickAgent.updateOnlineConfig(this);
		
	}
	
	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart( mPageName );
		MobclickAgent.onResume(mContext);
	}
	
	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd( mPageName );
		MobclickAgent.onPause(mContext);
	}
	/**
	 * android:onClick="onButtonClick"
	 * @param view
	 */
	public void onButtonClick(View view){
		int id = view.getId();
		switch( id){
		case R.id.umeng_example_analytics_online_config:
			
			String onlineParams= MobclickAgent.getConfigParams(mContext, "abc");//the demo param's key is 'abc'
			if(onlineParams.equals("")){
				Toast.makeText(mContext, "Get No Online Params", Toast.LENGTH_SHORT).show();
			}else
				Toast.makeText(mContext, "Online Params:"  onlineParams, Toast.LENGTH_SHORT).show();
			break;
		case R.id.umeng_example_analytics_event:
			MobclickAgent.onEvent(mContext, "click");
			MobclickAgent.onEvent(mContext, "click", "button");
			break;
		case R.id.umeng_example_analytics_ekv:
			Map<String, String> map_ekv = new HashMap<String, String>();
			map_ekv.put("type", "popular");
			map_ekv.put("artist", "JJLin");
			
			MobclickAgent.onEvent(mContext, "music", map_ekv);
			break;
		case R.id.umeng_example_analytics_duration:
			
// 			'MobclickAgent.onEventDuration' is deprecated, pls use 'MobclickAgent.onEventValue' instead.			
//			MobclickAgent.onEventDuration(mContext, "book", 12000);
//			MobclickAgent.onEventDuration(mContext, "book", "chapter1", 23000);
//			
//			Map<String, String> map_du = new HashMap<String, String>();
//			map_du.put("type", "popular");
//			map_du.put("artist", "JJLin");
//			
//			MobclickAgent.onEventDuration(mContext, "music", map_du, 2330000);
			
			Map<String, String> map_value = new HashMap<String, String>();
			map_value.put("type", "popular");
			map_value.put("artist", "JJLin");
			
			MobclickAgent.onEventValue(this, "music", map_value, 12000);
			break;
		case R.id.umeng_example_analytics_event_begin:
			//when the events start
			MobclickAgent.onEventBegin(mContext, "music");
			
			MobclickAgent.onEventBegin(mContext, "music", "one");
			
			Map<String, String> map = new HashMap<String, String>();
			map.put("type", "popular");
			map.put("artist", "JJLin");
			
			MobclickAgent.onKVEventBegin(mContext, "music", map, "flag0");
			break;
		case R.id.umeng_example_analytics_event_end:
			
			MobclickAgent.onEventEnd(mContext, "music");
			MobclickAgent.onEventEnd(mContext, "music", "one");	
			
			MobclickAgent.onKVEventEnd(mContext, "music", "flag0");
			break;
		case R.id.umeng_example_analytics_make_crash:
			"123".substring(10);
			break;
		case R.id.umeng_example_analytics_js_analytic:
			startActivity( new Intent( this, WebviewAnalytic.class) );
			break;
		case R.id.umeng_example_analytics_flush:
			MobclickAgent.flush(this);
			break;
		case R.id.umeng_example_analytics_fragment_stack:
			startActivity( new Intent(this, FragmentStack.class));
			break;
		case R.id.umeng_example_analytics_fragment_tabs:
			startActivity( new Intent(this, FragmentTabs.class));
			break;
		case R.id.umeng_example_analytics_social:
			
			UMPlatformData platform = new UMPlatformData(UMedia.WEIXIN_CIRCLE, "user_id");
			platform.setGender(GENDER.MALE); //optional
			platform.setWeiboId("weiboId");  //optional
			
			MobclickAgent.onSocialEvent(this, platform);
			break;
		}
	}

	@Override
	protected Fragment onCreatePane() {
		return new AnalyticsHomeDashboardFragment();	
	}
	
	public static class AnalyticsHomeDashboardFragment extends Fragment {
		
		@Override
	    public void onAttach(Activity activity) {
	        super.onAttach(activity);
	    }
		
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			return inflater.inflate(R.layout.umeng_example_analytics, container,false);
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Hook();
			return true;
		}
		
		return super.onKeyDown(keyCode, event);
	}

	///对于好多应用,会在程序中杀死 进程,这样会导致我们统计不到此时Activity结束的信息,
	///对于这种情况需要调用 'MobclickAgent.onKillProcess( Context )'
	///方法,保存一些页面调用的数据。正常的应用是不需要调用此方法的。
	private void Hook(){
		 AlertDialog.Builder builder = new AlertDialog.Builder( mContext );    
	        builder.setPositiveButton("退出应用",  
	                new DialogInterface.OnClickListener() {  
	                    public void onClick(DialogInterface dialog, int whichButton) {  
	                    	MobclickAgent.onKillProcess( mContext );
	                    	
	                    	int pid = android.os.Process.myPid();
	            			android.os.Process.killProcess(pid);
	                    }  
	                });  
	        builder.setNeutralButton("后退一下",  
	                new DialogInterface.OnClickListener() {  
	                    public void onClick(DialogInterface dialog, int whichButton) {  
	                        finish();
	                    }  
	                });  
	        builder.setNegativeButton("点错了",  
	                new DialogInterface.OnClickListener() {  
	                    public void onClick(DialogInterface dialog, int whichButton) {  
	                    }  
	                });  
	        builder.show();
	}
}

资源截图

代码片段和文件信息

/*
 * Copyright (C) 2010 Johan Nilsson 
 *
 * Licensed under the Apache License Version 2.0 (the “License“);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing software
 * distributed under the License is distributed on an “AS IS“ BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.markupartist.android.widget;

import java.util.linkedList;

import android.content.ActivityNotFoundException;
import android.content.Conte

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-04-09 15:53  res\
     目录           0  2014-04-09 15:53  res\anim\
     文件         279  2014-04-09 15:53  res\anim\umeng_fb_slide_in_from_left.xml
     文件         281  2014-04-09 15:53  res\anim\umeng_fb_slide_in_from_right.xml
     文件         280  2014-04-09 15:53  res\anim\umeng_fb_slide_out_from_left.xml
     文件         278  2014-04-09 15:53  res\anim\umeng_fb_slide_out_from_right.xml
     目录           0  2014-04-09 15:53  res\drawable\
     文件         294  2014-04-09 15:53  res\drawable\umeng_common_gradient_green.xml
     文件         294  2014-04-09 15:53  res\drawable\umeng_common_gradient_orange.xml
     文件         294  2014-04-09 15:53  res\drawable\umeng_common_gradient_red.xml
     文件        1172  2014-04-09 15:53  res\drawable\umeng_fb_arrow_right.png
     文件        1476  2014-04-09 15:53  res\drawable\umeng_fb_back_normal.png
     文件        1578  2014-04-09 15:53  res\drawable\umeng_fb_back_selected.png
     文件         472  2014-04-09 15:53  res\drawable\umeng_fb_back_selector.xml
     文件         229  2014-04-09 15:53  res\drawable\umeng_fb_bar_bg.9.png
     文件         477  2014-04-09 15:53  res\drawable\umeng_fb_btn_bg_selector.xml
     文件        8431  2014-04-09 15:53  res\drawable\umeng_fb_conversation_bg.png
     文件         294  2014-04-09 15:53  res\drawable\umeng_fb_gradient_green.xml
     文件         294  2014-04-09 15:53  res\drawable\umeng_fb_gradient_orange.xml
     文件         368  2014-04-09 15:53  res\drawable\umeng_fb_gray_frame.xml
     文件         322  2014-04-09 15:53  res\drawable\umeng_fb_list_item.9.png
     文件         328  2014-04-09 15:53  res\drawable\umeng_fb_list_item_pressed.9.png
     文件         313  2014-04-09 15:53  res\drawable\umeng_fb_list_item_selector.xml
     文件        3939  2014-04-09 15:53  res\drawable\umeng_fb_logo.png
     文件         310  2014-04-09 15:53  res\drawable\umeng_fb_point_new.xml
     文件         310  2014-04-09 15:53  res\drawable\umeng_fb_point_normal.xml
     文件        2979  2014-04-09 15:53  res\drawable\umeng_fb_reply_left_bg.9.png
     文件         265  2014-04-09 15:53  res\drawable\umeng_fb_reply_right_bg.9.png
     文件         949  2014-04-09 15:53  res\drawable\umeng_fb_see_list_normal.png
     文件        1059  2014-04-09 15:53  res\drawable\umeng_fb_see_list_pressed.png
     文件         314  2014-04-09 15:53  res\drawable\umeng_fb_see_list_selector.xml
............此处省略418个文件信息

评论

共有 条评论