Pgyer document center

Android SDK 集成指南

General

This article describes on how to integrate PgyerSDK into your Android apps. It allows testers to update your app to another beta version right from within the application. It will notify the tester if a new update is available. It also allows to send feedback and crash reports right from within the application. If a crash has happened, it will send information about the crash to the server immediately.

Get AppID

App ID: the ID that uniquely identifies an App in payer.com, developers can get App ID from application manage page.

App ID

Add PgyerSDK

For Eclipse Users

Download Pgyer Android SDK

Copy pgyersdk.jar to your project‘s libs directory.

libs directory

For Android Studio Users add the following codes into the build.gradle file in your project:

allprojects {
    repositories {
        jcenter()
        maven { url "https://raw.githubusercontent.com/Pgyer/mvn_repo_pgyer/master" }
    }
}

Then add the dependency into build.gradle files in your module:

dependencies {
    compile 'com.pgyersdk:sdk:2.8.0'
}

Android Studio Demo

In addition to the above method 'Android Studio' users also can use the same methods with 'Eclipse' users.

Configure the file of AndroidManifest.xml

<!-- Required -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.GET_TASKS"/>

<!-- Optional -->
<uses-permission android:name="android.permission.READ_LOGS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
<!-- Optional -->
    <activity android:name="com.pgyersdk.activity.FeedbackActivity"/>

<!-- Required -->
    <meta-data
        android:name="PGYER_APPID"
        android:value="4b6e8877dfcc2462bedb37dcf66b6d87" >
    </meta-data>
</application>

Crash Report

一、Register crash report method(Required)

  1. Add the following codes in your application,you can catch exception as soon as possible(recommended)
import com.pgyersdk.crash.PgyCrashManager;
import android.app.Application;

public class PgyApplication extends Application {

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();

        PgyCrashManager.register(this);
    }
}

Don't forget to replace android:name=".PgyApplication with your application name in the file of AndroidManifest.xml

<application
    android:name=".PgyApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.pgyer.pgyersdk.test.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

2. Add the following codes in your activity.

import com.pgyersdk.crash.PgyCrashManager;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        PgyCrashManager.register(this);
    }
}

二、Symbolicating Stack Traces(optional)

Find proguard/mapping.txt from your project directory.

Upload the file proguard/mapping.txt to your app's page.

Reported catch exceptions

try 
{
} 
catch (Exception e) 
{
    PgyCrashManager.reportCaughtException(MainActivity.this, e);            
}

shake your device to feedback

  1. Add the following codes in your activity.
import com.pgyersdk.feedback.PgyFeedbackShakeManager;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        // custom sensitivity, defaults to 950, the smaller the number higher sensitivity.
        PgyFeedbackShakeManager.setShakingThreshold(1000);

        // Open as a dialog
        PgyFeedbackShakeManager.register(MainActivity.this);

        //  Open as an Activity, in the case you must configure FeedbackActivity in the file of AndroidManifest.xml 
        PgyFeedbackShakeManager.register(MainActivity.this, false);

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        PgyFeedbackShakeManager.unregister();
    }
}
  1. You also need to add the following code in this file GLSurfaceView.Renderer.
public void onDrawFrame(GL10 gl) {
    PgyFeedbackShakeManager.setGLSurface(true);
    GLSurfaceUtils.getInstance().takeScreenShot(gl);
}
  1. feedback by clicking a button.
// Open as a dialog
PgyFeedback.getInstance().show(MainActivity.this);

 //  Open as an Activity, in the case you must configure FeedbackActivity in the file of AndroidManifest.xml
PgyFeedback.getInstance().showActiivty(MainActivity.this);

  1. Custom feedback dialog title
PgyerDialog.setDialogTitleBackgroundColor("#ff0000");
PgyerDialog.setDialogTitleTextColor("#ffffff");
  1. Custom feedback page
// Set navigation and bottom bar background
FeedbackActivity.setBarBackgroundColor("#ff0000");

// Set button backgournd when pressed.
FeedbackActivity.setBarButtonPressedColor("#ff0000");

// Set color picker background
FeedbackActivity.setColorPickerBackgroundColor("#ff0000");

Version Update

  1. Default version check
   PgyUpdateManager.register(this);
  1. Custom version check
   PgyUpdateManager.register(MainActivity.this,
   new UpdateManagerListener() {

      @Override
      public void onUpdateAvailable(final String result) {

        // Encapsulates new version information into AppBean
        final AppBean appBean = getAppBeanFromString(result);
        new AlertDialog.Builder(MainActivity.this)
            .setTitle("Update Available")
            .setMessage("")
            .setNegativeButton(
                    "OK",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(
                                DialogInterface dialog,
                                int which) {
                            startDownloadTask(
                                    MainActivity.this,
                                    appBean.getDownloadURL());
                        }
                    }).show();
      }

      @Override
      public void onNoUpdateAvailable() {
      }
   });

ProGuard

-libraryjars libs/pgyer_sdk_android_2.8.0.jar
-dontwarn com.pgyersdk.**
-keep class com.pgyersdk.** { *; }