这段代码用于向Skype发送消息,但是如果我没有Skype,我不知道如何设置https://play.google.com/store/apps/details?id=com.skype.raider。
skypename.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Uri skypeUri = Uri.parse("skype:username?chat"); Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri); myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main")); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(myIntent); } });
添加了代码...................................................... ................................................... 。
skypename.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!isSkypeClientInstalled(activity)) { Context activity; goToMarket(activity); return; } else{ Uri skypeUri = Uri.parse("skype:username?chat"); Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri); myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main")); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(myIntent); } public void goToMarket(Context myContext) { Activity activity; try { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "com.skype.raider"))); } catch (android.content.ActivityNotFoundException anfe) { activity. startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + "com.skype.raider"))); } return; } public boolean isSkypeClientInstalled(Context myContext) { PackageManager myPackageMgr = myContext.getPackageManager(); try { myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES); } catch (PackageManager.NameNotFoundException e) { return (false); } return (true); });
首先,您检查Skype是否已安装或未使用此代码。如果安装了味精,则转到Google Play下载Skype
skypename.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!isSkypeClientInstalled(MainActivity.this)) { goToMarket(MainActivity.this); return; } else{ Uri skypeUri = Uri.parse("skype:username?chat"); Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri); myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main")); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(myIntent); } } }); public void goToMarket(Context myContext) { try { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "com.skype.raider"))); } catch (android.content.ActivityNotFoundException anfe) { activity. startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + "com.skype.raider"))); } return; } public boolean isSkypeClientInstalled(Context myContext) { PackageManager myPackageMgr = myContext.getPackageManager(); try { myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES); } catch (PackageManager.NameNotFoundException e) { return (false); } return (true); }