差别
这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
cs:300visitoraccess:appopenurl [2017/05/20 03:07] liyuzhao 创建 |
cs:300visitoraccess:appopenurl [2017/08/02 09:26] liulj [Android 端客服工作台注册接收未读数广播] |
||
---|---|---|---|
行 7: | 行 7: | ||
<code> | <code> | ||
- | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("easemob://xxxx"))); | + | private void doStartApplicationWithPackageName(String packagename) { |
+ | |||
+ | // 通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等 | ||
+ | PackageInfo packageinfo = null; | ||
+ | try { | ||
+ | packageinfo = getPackageManager().getPackageInfo(packagename, 0); | ||
+ | } catch (PackageManager.NameNotFoundException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | if (packageinfo == null) { | ||
+ | Toast.makeText(this, "应用未安装", Toast.LENGTH_SHORT).show(); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent | ||
+ | Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); | ||
+ | resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); | ||
+ | resolveIntent.setPackage(packageinfo.packageName); | ||
+ | |||
+ | // 通过getPackageManager()的queryIntentActivities方法遍历 | ||
+ | List<ResolveInfo> resolveinfoList = getPackageManager() | ||
+ | .queryIntentActivities(resolveIntent, 0); | ||
+ | |||
+ | ResolveInfo resolveinfo = resolveinfoList.iterator().next(); | ||
+ | if (resolveinfo != null) { | ||
+ | // packagename = 参数packname | ||
+ | String packageName = resolveinfo.activityInfo.packageName; | ||
+ | // 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname] | ||
+ | String className = resolveinfo.activityInfo.name; | ||
+ | // LAUNCHER Intent | ||
+ | Intent intent = new Intent(Intent.ACTION_MAIN); | ||
+ | intent.addCategory(Intent.CATEGORY_LAUNCHER); | ||
+ | |||
+ | // 设置ComponentName参数1:packagename参数2:MainActivity路径 | ||
+ | ComponentName cn = new ComponentName(packageName, className); | ||
+ | |||
+ | intent.setComponent(cn); | ||
+ | startActivity(intent); | ||
+ | } | ||
+ | } | ||
+ | // 执行这句即可 | ||
+ | doStartApplicationWithPackageName("com.easemob.helpdesk"); | ||
</code> | </code> | ||
行 21: | 行 62: | ||
{{:cs:300visitoraccess:iosopenurl2.png?500|}} | {{:cs:300visitoraccess:iosopenurl2.png?500|}} | ||
+ | ===== Android 端客服工作台注册接收未读数广播 ===== | ||
+ | 可以动态注册,也可以在AndroidManifest.xml中注册,只需要指定对Action即可,在此只举一个例子: | ||
+ | <code> | ||
+ | //1. 在AndroidManifest.xml注册广播 | ||
- | + | <receiver android:name=".NewMessageReceive"> | |
+ | <intent-filter> | ||
+ | <action android:name="com.easemob.helpdesk.newmessage"/> | ||
+ | </intent-filter> | ||
+ | |||
+ | </receiver> | ||
+ | |||
+ | // 2. 继承自BroadcastReceiver的类,根据extra获取unreadcount | ||
+ | |||
+ | public class NewMessageReceive extends BroadcastReceiver { | ||
+ | @Override | ||
+ | public void onReceive(Context context, Intent intent) { | ||
+ | int count = intent.getIntExtra("com.easemob.helpdesk.unreadcount", 0); | ||
+ | Toast.makeText(context.getApplicationContext(), "收到消息->" + count, Toast.LENGTH_SHORT).show(); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </code> |