Start Google Hangout from Intent in New Hangouts Android app

后端 未结 5 693
终归单人心
终归单人心 2020-11-30 06:03

There are previous discussions here regarding starting a Google Hangout from an intent on Android: start google hangouts in android

How can I start a Google Hangout

5条回答
  •  一生所求
    2020-11-30 06:22

    try in this way

    Below method use to share text to hangout

    /**
     * Initiate the actions encoded in the specified URI.
     */
    public void initiateHangOutUri(Context myContext, String textToShare) {
    
      // Make sure Android client is installed.
      if (!isHangOutClientInstalled(myContext)) {
        goToMarket(myContext);
        return;
      }
    
      Intent sendIntent = new Intent();
      sendIntent.setAction(Intent.ACTION_SEND);
      sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
      sendIntent.setType("text/plain");
      sendIntent.setPackage("com.google.android.talk");
      context.startActivity(sendIntent);
    
      return;
    }
    

    Below method use to check HangOut installed on this device

    /**
     * Determine whether the HangOut for Android client is installed on this device.
     **/
    public boolean isHangOutClientInstalled(Context myContext) {
      final PackageManager packageManager = context.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage("com.google.android.talk");
        if (intent == null) {
            return false;
        }
        List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    

    Below method use goto playstore if HangOut not installed

    public void goToMarket(Context myContext) {
      Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
      Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
      myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      myContext.startActivity(myIntent);
    
      return;
    }
    

提交回复
热议问题