Przeglądaj źródła

add yunba push library

wangxl 9 lat temu
rodzic
commit
bcc562780a

+ 21 - 0
display-client/AndroidManifest.xml

@ -37,6 +37,9 @@
37 37
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
38 38
    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
39 39
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
40
    
41
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
42
    <uses-permission android:name="android.permission.WAKE_LOCK" />
40 43

41 44
    <application
42 45
        android:allowBackup="true"
@ -116,6 +119,24 @@
116 119
            android:name="com.wade.mobile.common.map.activity.SelectLocationActivity"
117 120
            android:screenOrientation="portrait" >
118 121
        </activity>
122
        
123
         <!-- YunBa Start -->
124

125
        <meta-data
126
            android:name="YUNBA_APPKEY"
127
            android:value="5630418ff085fc471efdf2c9" />
128

129
        <service android:name="io.yunba.android.core.YunBaService" >
130
        </service>
131

132
        <receiver android:name="io.yunba.android.core.YunBaReceiver" >
133
            <intent-filter>
134
                <action android:name="android.intent.action.USER_PRESENT" />
135
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
136
            </intent-filter>
137
        </receiver>
138
        
139
        <!-- YunBa End -->
119 140
    </application>
120 141

121 142
</manifest>

+ 6 - 0
display-client/assets/mobile-action.xml

@ -101,10 +101,16 @@
101 101
	<action name="selectFirst" class="com.wade.mobile.func.MobileDB" method="selectFirst"></action>
102 102
	
103 103
	<!-- MobilePush -->
104
	<!-- 
104 105
	<action name="registerForPush" class="com.ai.mobile.im.func.MobilePush" method="registerForPush"></action>
105 106
	<action name="unregisterForPush" class="com.ai.mobile.im.func.MobilePush" method="unregisterForPush"></action>
106 107
	<action name="sendText" class="com.ai.mobile.im.func.MobilePush" method="sendText"></action>
107 108
	<action name="setCallbackForPush" class="com.ai.mobile.im.func.MobilePush" method="setCallbackForPush"></action>
109
	 -->
110
	<action name="registerForPushWithYunba"    class="com.ai.ipu.mobile.push.YunBaPush" method="registerForPush"></action>
111
	<action name="unregisterForPushWithYunba"  class="com.ai.ipu.mobile.push.YunBaPush" method="unregisterForPush"></action>
112
	<action name="sendTextWithYunba"           class="com.ai.ipu.mobile.push.YunBaPush" method="sendText"></action>
113
	<action name="setCallbackForPushWithYunba" class="com.ai.ipu.mobile.push.YunBaPush" method="setCallbackForPush"></action>
108 114
	
109 115
	<action name="getContacts" class="com.wade.mobile.func.MobileContactDetail" method="getContacts"></action>
110 116
</actions>

+ 7 - 0
wade-mobile-push-yunba/.gitignore

@ -0,0 +1,7 @@
1
/.settings
2
/bin
3
/gen
4
/proguard
5
/.classpath
6
7
/project.properties

+ 33 - 0
wade-mobile-push-yunba/.project

@ -0,0 +1,33 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>wade-mobile-push-yunba</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.jdt.core.javabuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
29
	<natures>
30
		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31
		<nature>org.eclipse.jdt.core.javanature</nature>
32
	</natures>
33
</projectDescription>

+ 17 - 0
wade-mobile-push-yunba/AndroidManifest.xml

@ -0,0 +1,17 @@
1
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
    package="com.ai.ipu.mobile.push"
3
    android:versionCode="1"
4
    android:versionName="1.0" >
5
6
    <uses-sdk
7
        android:minSdkVersion="8"
8
        android:targetSdkVersion="15" />
9
10
    <application
11
        android:allowBackup="true"
12
        android:icon="@drawable/ic_launcher"
13
        android:label="@string/app_name"
14
        android:theme="@style/AppTheme" >
15
    </application>
16
17
</manifest>

BIN
wade-mobile-push-yunba/libs/android-support-v4.jar


BIN
wade-mobile-push-yunba/libs/yunba-sdk-release1.4.5.jar


+ 20 - 0
wade-mobile-push-yunba/proguard-project.txt

@ -0,0 +1,20 @@
1
# To enable ProGuard in your project, edit project.properties
2
# to define the proguard.config property as described in that file.
3
#
4
# Add project specific ProGuard rules here.
5
# By default, the flags in this file are appended to flags specified
6
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7
# You can edit the include path and order by changing the ProGuard
8
# include property in project.properties.
9
#
10
# For more details, see
11
#   http://developer.android.com/guide/developing/tools/proguard.html
12
13
# Add any project specific keep options here:
14
15
# If your project uses WebView with JS, uncomment the following
16
# and specify the fully qualified class name to the JavaScript interface
17
# class:
18
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19
#   public *;
20
#}

+ 18 - 0
wade-mobile-push-yunba/readme.md

@ -0,0 +1,18 @@
1
 ### 添加以下代码到主工程,YUNBA_APPKEY 需要到云巴官网申请
2
 <!-- YunBa Start -->
3
4
	<meta-data
5
	    android:name="YUNBA_APPKEY"
6
	    android:value="55f8e4994a481fa955f393e4" />
7
	
8
	<service android:name="io.yunba.android.core.YunBaService" >
9
	</service>
10
	
11
	<receiver android:name="io.yunba.android.core.YunBaReceiver" >
12
	    <intent-filter>
13
	        <action android:name="android.intent.action.USER_PRESENT" />
14
	        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
15
	    </intent-filter>
16
	</receiver>
17
18
<!-- YunBa End -->

BIN
wade-mobile-push-yunba/res/drawable-hdpi/ic_launcher.png


BIN
wade-mobile-push-yunba/res/drawable-mdpi/ic_launcher.png


BIN
wade-mobile-push-yunba/res/drawable-xhdpi/ic_launcher.png


+ 11 - 0
wade-mobile-push-yunba/res/values-v11/styles.xml

@ -0,0 +1,11 @@
1
<resources>
2
3
    <!--
4
        Base application theme for API 11+. This theme completely replaces
5
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
6
    -->
7
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8
        <!-- API 11 theme customizations can go here. -->
9
    </style>
10
11
</resources>

+ 12 - 0
wade-mobile-push-yunba/res/values-v14/styles.xml

@ -0,0 +1,12 @@
1
<resources>
2
3
    <!--
4
        Base application theme for API 14+. This theme completely replaces
5
        AppBaseTheme from BOTH res/values/styles.xml and
6
        res/values-v11/styles.xml on API 14+ devices.
7
    -->
8
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9
        <!-- API 14 theme customizations can go here. -->
10
    </style>
11
12
</resources>

+ 5 - 0
wade-mobile-push-yunba/res/values/strings.xml

@ -0,0 +1,5 @@
1
<resources>
2
3
    <string name="app_name">wade-mobile-push-yunba</string>
4
5
</resources>

+ 20 - 0
wade-mobile-push-yunba/res/values/styles.xml

@ -0,0 +1,20 @@
1
<resources>
2
3
    <!--
4
        Base application theme, dependent on API level. This theme is replaced
5
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6
    -->
7
    <style name="AppBaseTheme" parent="android:Theme.Light">
8
        <!--
9
            Theme customizations available in newer API levels can go in
10
            res/values-vXX/styles.xml, while customizations related to
11
            backward-compatibility can go here.
12
        -->
13
    </style>
14
15
    <!-- Application theme. -->
16
    <style name="AppTheme" parent="AppBaseTheme">
17
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
18
    </style>
19
20
</resources>

+ 268 - 0
wade-mobile-push-yunba/src/com/ai/ipu/mobile/push/YunBaPush.java

@ -0,0 +1,268 @@
1
package com.ai.ipu.mobile.push;
2
3
import io.yunba.android.manager.YunBaManager;
4
5
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
6
import org.eclipse.paho.client.mqttv3.IMqttToken;
7
import org.eclipse.paho.client.mqttv3.MqttException;
8
import org.json.JSONArray;
9
import org.json.JSONException;
10
import org.json.JSONObject;
11
12
import android.content.BroadcastReceiver;
13
import android.content.Context;
14
import android.content.Intent;
15
import android.content.IntentFilter;
16
import android.util.Log;
17
18
import com.ai.mobile.im.PushManager;
19
import com.ai.mobile.im.util.PushSharedPrefHelper;
20
import com.wade.mobile.frame.IWadeMobile;
21
import com.wade.mobile.frame.plugin.Plugin;
22
import com.wade.mobile.helper.SharedPrefHelper;
23
import com.wade.mobile.util.EscapeUnescape;
24
25
public class YunBaPush extends Plugin {
26
27
	private final String PUSH_CALLBACK = "PUSH_CALLBACK";
28
29
	private BroadcastReceiver msgReceiver;
30
31
	private String topic = "IPU";
32
33
	private String alias;
34
35
	public YunBaPush(IWadeMobile wademobile) {
36
		super(wademobile);
37
	}
38
39
	public void registerForPush(JSONArray param) throws Exception {
40
41
		/* YunBa Start */
42
		YunBaManager.start(context.getApplicationContext());
43
44
		// 订阅
45
		subscribeTopic(new String[] { topic });
46
47
		// 注册昵称
48
		alias = param.getString(0);
49
		reigisterYuBaAlias(alias);
50
51
		// Receiver
52
		registerYuBaReceiver();
53
54
		/* YunBa End */
55
56
	}
57
58
	private void subscribeTopic(String[] topics) {
59
		YunBaManager.subscribe(context.getApplicationContext(), topics,
60
				new IMqttActionListener() {
61
62
					@Override
63
					public void onSuccess(IMqttToken arg0) {
64
						YunBaUtil.showToast("连接成功", context);
65
						YunBaPush.this.callback("SUC");
66
					}
67
68
					@Override
69
					public void onFailure(IMqttToken arg0, Throwable arg1) {
70
						Log.d(TAG, "Subscribe topic failed");
71
					}
72
				});
73
	}
74
75
	private void reigisterYuBaAlias(String alias) {
76
		if (YunBaUtil.isEmpty(alias)) {
77
			YunBaUtil.showToast("alias不能为空", context);
78
			return;
79
		}
80
		YunBaManager.setAlias(context.getApplicationContext(), alias,
81
				new IMqttActionListener() {
82
					@Override
83
					public void onSuccess(IMqttToken asyncActionToken) {
84
						Log.d(TAG, "success");
85
					}
86
87
					@Override
88
					public void onFailure(IMqttToken asyncActionToken,
89
							Throwable exception) {
90
						if (exception instanceof MqttException) {
91
							MqttException ex = (MqttException) exception;
92
							String msg = "setAlias failed with error code : "
93
									+ ex.getReasonCode();
94
							YunBaUtil.showToast(msg,
95
									context.getApplicationContext());
96
						}
97
					}
98
				});
99
	}
100
101
	private void registerYuBaReceiver() {
102
		if (msgReceiver == null) {
103
			msgReceiver = new BroadcastReceiver() {
104
105
				@Override
106
				public void onReceive(Context context, Intent intent) {
107
108
					if (YunBaManager.MESSAGE_RECEIVED_ACTION.equals(intent
109
							.getAction())) {
110
						String topic = intent
111
								.getStringExtra(YunBaManager.MQTT_TOPIC);
112
						String msg = intent
113
								.getStringExtra(YunBaManager.MQTT_MSG);
114
115
						//  在这里处理从服务器发布下来的消息, 比如显示通知栏, 打开 Activity 等等
116
						StringBuilder showMsg = new StringBuilder();
117
						showMsg.append("Received message from server: ")
118
								.append(YunBaManager.MQTT_TOPIC).append(" = ")
119
								.append(topic).append(" ")
120
								.append(YunBaManager.MQTT_MSG).append(" = ")
121
								.append(msg);
122
						// YunBaUtil.showNotifation(context, topic, msg);
123
						Log.d("", showMsg.toString());
124
						try {
125
							String aliasStr = null;
126
							String contentStr = null;
127
							String resultStr = null;
128
							if (!msg.startsWith("{")) {
129
								resultStr = "{\"ALIAS\":\"匿名用户\",\"MSG\":\""
130
										+ msg + "\"}";
131
							} else {
132
								JSONObject msgJson = new JSONObject(msg);
133
								aliasStr = msgJson.getString("ALIAS");
134
								contentStr = msgJson.getString("MSG");
135
136
								aliasStr = YunBaUtil.isEmpty(aliasStr) ? "匿名用户"
137
										: aliasStr;
138
139
								resultStr = "{\"ALIAS\":\"" + aliasStr
140
										+ "\",\"MSG\":\"" + contentStr + "\"}";
141
							}
142
143
							sendCallbackMsg(resultStr);
144
						} catch (JSONException e) {
145
							e.printStackTrace();
146
						}
147
148
					}else if(YunBaManager.PRESENCE_RECEIVED_ACTION.equals(intent.getAction())) {
149
						 //此消息由当前客户端发出,暂时不处理
150
						
151
							
152
					}
153
				}
154
			};
155
156
			IntentFilter msgFilter = new IntentFilter();
157
			msgFilter.addAction("io.yunba.android.MESSAGE_RECEIVED_ACTION");
158
			msgFilter.addCategory(context.getPackageName());
159
			context.registerReceiver(msgReceiver, msgFilter);
160
		}
161
	}
162
163
	public void unregisterForPush(JSONArray param) {
164
165
		if (msgReceiver != null) {
166
			context.unregisterReceiver(msgReceiver);
167
			msgReceiver = null;
168
169
			YunBaManager.unsubscribe(context.getApplicationContext(),
170
					new String[] { topic }, new IMqttActionListener() {
171
172
						@Override
173
						public void onSuccess(IMqttToken arg0) {
174
							Log.d(TAG, "unsubscribe topic succeed");
175
						}
176
177
						@Override
178
						public void onFailure(IMqttToken arg0, Throwable arg1) {
179
							Log.d(TAG, "unsubscribe topic failed");
180
						}
181
					});
182
		}
183
	}
184
185
	@Override
186
	public void onStop() {
187
		YunBaManager.stop(context.getApplicationContext());
188
		super.onStop();
189
	}
190
191
	public void setCallbackForPush(JSONArray param) throws Exception {
192
		String callback = param.getString(0);
193
		new SharedPrefHelper(context).put(PushManager.PUSH_STORAGE,
194
				PUSH_CALLBACK, callback);
195
	}
196
197
	public void sendText(JSONArray param) throws Exception {
198
		String receiver = param.getString(0);
199
		String msg = param.getString(1);
200
		final String content = "{\"ALIAS\":\"" + alias + "\",\"MSG\":\"" + msg
201
				+ "\"}";
202
		if ("ALL".equals(receiver)) {
203
			YunBaManager.publish(context.getApplicationContext(), topic,
204
					content, new IMqttActionListener() {
205
						@Override
206
						public void onSuccess(IMqttToken asyncActionToken) {
207
							String topic = YunBaUtil.join(
208
									asyncActionToken.getTopics(), ", ");
209
							String msgLog = "publish to alias succeed : "
210
									+ topic;
211
							YunBaUtil.showToast(msgLog,
212
									context.getApplicationContext());
213
							YunBaPush.this.callback("SUC");
214
						}
215
216
						@Override
217
						public void onFailure(IMqttToken asyncActionToken,
218
								Throwable exception) {
219
							if (exception instanceof MqttException) {
220
								MqttException ex = (MqttException) exception;
221
								String msg = "publishToAlias failed with error code : "
222
										+ ex.getReasonCode();
223
								YunBaUtil.showToast(msg,
224
										context.getApplicationContext());
225
							}
226
						}
227
					});
228
		} else {
229
			YunBaManager.publishToAlias(context.getApplicationContext(),
230
					receiver, content, new IMqttActionListener() {
231
						@Override
232
						public void onSuccess(IMqttToken asyncActionToken) {
233
							String topic = YunBaUtil.join(
234
									asyncActionToken.getTopics(), ", ");
235
							String msgLog = "publish to alias succeed : "
236
									+ topic;
237
							YunBaUtil.showToast(msgLog,
238
									context.getApplicationContext());
239
							YunBaPush.this.callback("SUC");
240
							sendCallbackMsg(content);
241
						}
242
243
						@Override
244
						public void onFailure(IMqttToken asyncActionToken,
245
								Throwable exception) {
246
							if (exception instanceof MqttException) {
247
								MqttException ex = (MqttException) exception;
248
								String msg = "publishToAlias failed with error code : "
249
										+ ex.getReasonCode();
250
								YunBaUtil.showToast(msg,
251
										context.getApplicationContext());
252
							}
253
						}
254
					});
255
		}
256
257
	}
258
259
	private void sendCallbackMsg(String resultStr) {
260
		callback = PushSharedPrefHelper.get(wademobile.getActivity(),
261
				PushManager.PUSH_STORAGE, PUSH_CALLBACK, "alert");
262
		callback = "(function(msg){" + callback + "(unescape(msg));})";// 转义
263
264
		wademobile.getCurrentWebView().executeJs(
265
				callback + "('" + EscapeUnescape.escape(resultStr) + "')");
266
	}
267
268
}

+ 173 - 0
wade-mobile-push-yunba/src/com/ai/ipu/mobile/push/YunBaUtil.java

@ -0,0 +1,173 @@
1
package com.ai.ipu.mobile.push;
2
3
import io.yunba.android.manager.YunBaManager;
4
5
import java.util.List;
6
import java.util.Random;
7
8
import android.app.ActivityManager;
9
import android.app.ActivityManager.RunningAppProcessInfo;
10
import android.app.NotificationManager;
11
import android.app.PendingIntent;
12
import android.content.Context;
13
import android.content.Intent;
14
import android.content.pm.ApplicationInfo;
15
import android.content.pm.PackageManager;
16
import android.content.pm.PackageManager.NameNotFoundException;
17
import android.media.RingtoneManager;
18
import android.net.ConnectivityManager;
19
import android.net.NetworkInfo;
20
import android.net.Uri;
21
import android.os.Bundle;
22
import android.os.Looper;
23
import android.support.v4.app.NotificationCompat;
24
import android.support.v4.app.TaskStackBuilder;
25
import android.telephony.TelephonyManager;
26
import android.widget.Toast;
27
28
public class YunBaUtil {
29
	public static boolean isEmpty(String s) {
30
		if (null == s)
31
			return true;
32
		if (s.length() == 0)
33
			return true;
34
		if (s.trim().length() == 0)
35
			return true;
36
		return false;
37
	}
38
39
	public static boolean showNotifation(Context context, String topic,
40
			String msg) {
41
		try {
42
			Uri alarmSound = RingtoneManager
43
					.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
44
45
			long[] pattern = { 500, 500, 500 };
46
			NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
47
					context).setSmallIcon(R.drawable.ic_launcher)
48
					.setContentTitle(topic).setContentText(msg)
49
					.setSound(alarmSound).setVibrate(pattern)
50
					.setAutoCancel(true);
51
			// Creates an explicit intent for an Activity in your app
52
			Intent resultIntent = new Intent(context, context.getClass());
53
			if (!YunBaUtil.isEmpty(topic))
54
				resultIntent.putExtra(YunBaManager.MQTT_TOPIC, topic);
55
			if (!YunBaUtil.isEmpty(msg))
56
				resultIntent.putExtra(YunBaManager.MQTT_MSG, msg);
57
			// The stack builder object will contain an artificial back stack
58
			// for the
59
			// started Activity.
60
			// This ensures that navigating backward from the Activity leads out
61
			// of
62
			// your application to the Home screen.
63
			TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
64
			// Adds the back stack for the Intent (but not the Intent itself)
65
			stackBuilder.addParentStack(context.getClass());
66
			// Adds the Intent that starts the Activity to the top of the stack
67
			stackBuilder.addNextIntent(resultIntent);
68
			PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
69
					0, PendingIntent.FLAG_UPDATE_CURRENT);
70
//			mBuilder.setContentIntent(resultPendingIntent);
71
			NotificationManager mNotificationManager = (NotificationManager) context
72
					.getSystemService(Context.NOTIFICATION_SERVICE);
73
			// mId allows you to update the notification later on.
74
			Random r = new Random();
75
			mNotificationManager.notify(r.nextInt(), mBuilder.build());
76
		} catch (Exception e) {
77
			return false;
78
		}
79
		return true;
80
	}
81
82
	public static void showToast(final String toast, final Context context) {
83
		if (!isAppOnForeground(context))
84
			return;
85
		new Thread(new Runnable() {
86
87
			@Override
88
			public void run() {
89
				Looper.prepare();
90
				Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
91
				Looper.loop();
92
			}
93
		}).start();
94
	}
95
96
	public static boolean isAppOnForeground(Context context) {
97
		ActivityManager activityManager = (ActivityManager) context
98
				.getSystemService(Context.ACTIVITY_SERVICE);
99
		// Returns a list of application processes that are running on the
100
		// device
101
		List<RunningAppProcessInfo> appProcesses = activityManager
102
				.getRunningAppProcesses();
103
		if (appProcesses == null)
104
			return false;
105
		for (RunningAppProcessInfo appProcess : appProcesses) {
106
			// importance:
107
			// The relative importance level that the system places
108
			// on this process.
109
			// May be one of IMPORTANCE_FOREGROUND, IMPORTANCE_VISIBLE,
110
			// IMPORTANCE_SERVICE, IMPORTANCE_BACKGROUND, or IMPORTANCE_EMPTY.
111
			// These constants are numbered so that "more important" values are
112
			// always smaller than "less important" values.
113
			// processName:
114
			// The name of the process that this object is associated with.
115
			if (appProcess.processName.equals(context.getPackageName())
116
					&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
117
				return true;
118
			}
119
		}
120
		return false;
121
	}
122
123
	public static <T> String join(T[] array, String cement) {
124
		StringBuilder builder = new StringBuilder();
125
126
		if (array == null || array.length == 0) {
127
			return null;
128
		}
129
		for (T t : array) {
130
			builder.append(t).append(cement);
131
		}
132
133
		builder.delete(builder.length() - cement.length(), builder.length());
134
135
		return builder.toString();
136
	}
137
138
	public static boolean isNetworkEnabled(Context context) {
139
		ConnectivityManager conn = (ConnectivityManager) context
140
				.getSystemService(Context.CONNECTIVITY_SERVICE);
141
		NetworkInfo info = conn.getActiveNetworkInfo();
142
		return (info != null && info.isConnected());
143
	}
144
145
	public static String getImei(Context context, String imei) {
146
		TelephonyManager telephonyManager = (TelephonyManager) context
147
				.getSystemService(Context.TELEPHONY_SERVICE);
148
		imei = telephonyManager.getDeviceId();
149
		return imei;
150
	}
151
152
	public static String getAppKey(Context context) {
153
		Bundle metaData = null;
154
		String appKey = null;
155
		try {
156
			ApplicationInfo ai = context.getPackageManager()
157
					.getApplicationInfo(context.getPackageName(),
158
							PackageManager.GET_META_DATA);
159
			if (null != ai) {
160
				metaData = ai.metaData;
161
			}
162
			if (null != metaData) {
163
				appKey = metaData.getString("YUNBA_APPKEY");
164
				if ((null == appKey) || appKey.length() != 24) {
165
					appKey = "Error";
166
				}
167
			}
168
		} catch (NameNotFoundException e) {
169
170
		}
171
		return appKey;
172
	}
173
}