tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
405 stars 279 forks source link

Android support #4

Closed atticoos closed 5 years ago

atticoos commented 8 years ago

Thanks for putting together this package!

I'm in the process today in integrating Android on my fork. I'll throw a pull request your way at some point this week :smile:

adamrainsby commented 8 years ago

Any update on this? @ajwhite

frederickfogerty commented 8 years ago

Any update? @ajwhite ༼ つ ◕◕ ༽つ GIVE ANDROID ༼ つ ◕◕ ༽つ

atticoos commented 8 years ago

Sorry guys, dropped the ball on this. So ah.. 2 months later: https://github.com/asamiller/react-native-intercom/pull/7

frederickfogerty commented 8 years ago

Awesome @ajwhite! We're going to take a look at that PR and see if we can add to it. Thanks for your work :)

atticoos commented 8 years ago

Please do! This was just enough to cover what I needed, so there's certainly more that can be done :+1:

atticoos commented 8 years ago

7 has been merged.

However, it's not :100: in parity with iOS -- there's some features missing, such as message composing. Given that, not sure if this should be closed until Android is 1-1 with iOS.

browniefed commented 8 years ago

Yes we can hold off on closing this till we hit parity. I'll see about getting a major version bump and cutting a release tonight.

atticoos commented 8 years ago

Sounds good, thanks @browniefed!

browniefed commented 8 years ago

@ajwhite Do you think you could write up how to go about initializing the android version with an API key and such?

Haven't done much android work so not entirely certain where the call to Intercom.initialize should be.

atticoos commented 8 years ago

Surely - I'll also put together the instructions on how to include and compile the android version in as well. May have to come early next week

Partysun commented 8 years ago

@ajwhite Where Itercom.initialize should be in the Android source? 🆘 ;) --P.S. Solved!)

I have added new SampleApplication.java (ofc it's the should be your title;) file in src folder with MainActivity.java file.

package com.myawesomeapp;

import io.intercom.android.sdk.Intercom;
import android.app.Application;

public class SampleApplication extends Application {
    //CHANGE THESE VALUES
    private final String YOUR_API_KEY = "";
    private final String YOUR_APP_ID = "";

    @Override
    public void onCreate() {
        super.onCreate();
        Intercom.initialize(this, YOUR_API_KEY, YOUR_APP_ID);
    }
}

And also I've changed AndroidManifest file

...  
<application
        android:name=".SampleApplication"
        android:allowBackup="true"
...

And it works. I think to call init function in js will be a great approach, like HockeyApp integration, where simply call registration function in the method of react lifecycle.

atticoos commented 8 years ago

You can stick that right in the onCreate.

I personally have

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Intercom.initialize(
    getApplication(), 
    BuildConfig.INTERCOM_KEY,
    BuildConfig.INTERCOM_PROJECT
  );
}

Note: my key/project is derived from environment variables in the gradle build process. can just stick them in there obvi

Partysun commented 8 years ago

Thank you.) I hope somebody with the same noob problem can find this solution here)

atticoos commented 8 years ago

I really owe you guys a setup guide 😞 I'm sorry!

Soon ™️

dinodsaurus commented 8 years ago

Im still having some troubles setting up Intercom for android(ios works just fine), the thing I did is: MainApplicaiton.java

import io.intercom.android.sdk.Intercom;

private final String API_KEY = "";
  private final String APP_ID = "";

  @Override
  public void onCreate() {
    super.onCreate();
    Intercom.initialize(
      this,
      API_KEY,
      APP_ID
    );
  }

app/build.gradle

dependencies {
    compile project(':react-native-intercom')
}

settings.gradle

include ':react-native-intercom'
project(':react-native-intercom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-intercom/android')
atticoos commented 8 years ago

What troubles are you running into @dinodsaurus? Can you share some context of the error/problem?

dinodsaurus commented 8 years ago

First of all thanks for this quick response!

Build is successful but every time I try to call an Intercommethod that method is undefined

https://www.dropbox.com/s/ixeuz1iibjsf60w/Screenshot%202016-08-19%2016.51.03.png?dl=0

atticoos commented 8 years ago

Mind linking a gist of the file that produces this error?

caalle commented 8 years ago

I had a similar issue when adding it to my android application and solved by using getApplication instead of this.

Something like:

public class MainActivity extends ReactActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intercom.initialize(
            getApplication(),
            "<API_KEY>",
            "<APP_ID>"
        );
wrozka commented 8 years ago

@dinodsaurus I had to register IntercomPackage in MainApplication as well:

 protected List<ReactPackage> getPackages() {                                                  
     return Arrays.<ReactPackage>asList(                                                         
         new MainReactPackage(),                                                                 
         new IntercomPackage()                                                                   
    );                                                                                          
 } 
frexos commented 8 years ago

Hello everyone and thanks for the wrapper. Has anyone managed to successfully receive push notifications? I ve followed all the instructions - managed to successfully install intercom (am able to register and log out users) but still no push notifications.

dinodsaurus commented 8 years ago

Hey @ajwhite you can find my MainApplication.java here - https://gist.github.com/dinodsaurus/da6641d4be1af653619b6ff6afcead75

The error that Im getting now is

.../android/app/src/main/java/com/ivyspacestudent/MainApplication.java:22: error: cannot find symbol
  protected void onCreate(Bundle savedInstanceStat) {
                          ^
  symbol:   class Bundle
  location: class MainApplication
.../android/app/src/main/java/com/ivyspacestudent/MainApplication.java:21: error: method does not override or implement a method from a supertype
  @Override
  ^
marlonbrgomes commented 8 years ago

Im having the same error that @dinodsaurus. When I try to call the methods from Intercom, one error is dispatched on promise saying that method is undefined.

RN - 0.33 react-native-intercom - 3.0.3 MainApplication.java

import io.intercom.android.sdk.Intercom;
import android.app.Application;

public class SampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Intercom.initialize(this, API_KEY, APP_ID);
    }
}

app/build.gradle

dependencies { compile project(':react-native-intercom') }

settings.gradle

include ':react-native-intercom' project(':react-native-intercom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-intercom/android')

Edit: on iOS is working fine.

kageurufu commented 8 years ago

You need to add new IntercomPackage() to your MainApplication.getPackages()

// ...
import com.robinpowered.react.Intercom.IntercomPackage;

public class MainApplication extends Application implements ReactApplication {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          // ...
          new IntercomPackage()
      );
    }
  };
vitorebatista commented 8 years ago

Works here! Thanks all!

MainApplicaiton.java

import com.robinpowered.react.Intercom.IntercomPackage;
import io.intercom.android.sdk.Intercom;

  private final String API_KEY = "";
  private final String APP_ID = "";

  @Override
  public void onCreate() {
    super.onCreate();
    Intercom.initialize(
      this,
      API_KEY,
      APP_ID
    );
  }

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new IntercomPackage() 
    );
  }

app/build.gradle

dependencies {
    compile project(':react-native-intercom')
}

settings.gradle

include ':react-native-intercom'
project(':react-native-intercom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-intercom/android')
MattyK14 commented 7 years ago

I've like triple checked @vitorebatista's comment with my files, and I'm getting no where screenshot_1486584510

gioivan commented 4 years ago

You can stick that right in the onCreate.

I personally have

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Intercom.initialize(
    getApplication(), 
    BuildConfig.INTERCOM_KEY,
    BuildConfig.INTERCOM_PROJECT
  );
}

Note: my key/project is derived from environment variables in the gradle build process. can just stick them in there obvi

how do you get BuildConfig.INTERCOM_KEY ?