Shareinstall's Android SDK integration

Source: Internet
Author: User

Tip: The following code (configuration) is dynamically generated by Shareinstall based on the current application, and can be used directly by the developer, and the Android SDK integration will be completed in 10 minutes by following the steps below.

First, import the SDK

Android SDK Download v1.0.6 http://api.shareinstall.com/download/1.0.6/android

Android DEMO Download v1.0.6 Http://api.shareinstall.com/download/1.0.6/androiddemo

From the downloaded Shareinstallsdk.zip file, copy the Aar file to the project's Libs folder and import

dependencies {
Compile (name: ' shareinstall_1.0.5 ', ext: ' AAR ')
}

(Note: Import the AAR to check if the build file has added the following code, otherwise it will be an error)

repositories {
Flatdir {
Dirs ' Libs '
}
}

Second, the basic configuration

Add a permission declaration in Androidmainfest.xml.

<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>

Add the Appkey assigned to your app in the Application tab in Androidmainfest.xml

<meta-data
Android:name= "Com.shareinstall.APP_KEY"
Android:value= "K2bk7b6hh7f7r2"/>

Call the Shareinstall.getinstance (). Init (context) method in custom application to complete the initialization of the SDK, before initializing it to determine whether the current process is the main process of the application.

public class MyApp extends application {

@Overridepublic void onCreate() {    super.onCreate();    if (isMainProcess()) {        ShareInstall.getInstance().init(getApplicationContext());    }}/**    * 判断当前进程是否是应用的主进程    *    * @return    */public boolean isMainProcess() {    int pid = android.os.Process.myPid();    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {        if (appProcess.pid == pid) {            return getApplicationInfo().packageName.equals(appProcess.processName);        }    }    return false;}

}

If you use the registration statistics feature provided by the Shareinstall control Center, you can call Method Shareinstall.getinstance (). Reportregister (); Note that this method is called after the Shareinstall.getinstance (). Init (context) method, otherwise it throws an exception.

Invoking the Registered interface
Shareinstall.getinstance (). Reportregister ();

Add Android:name= "to the application tag in Androidmainfest.xml. MyApplication "Specifies the custom application class so that the custom application class is initialized when the program starts, not the system default application class.

Android:allowbackup= "false"
android:icon= "@mipmap/ic_launcher"
Application
Android:name= ". MyApplication "
Android:allowbackup= "false"
android:icon= "@mipmap/ic_launcher"
Br/>android:supportsrtl= "true"
Android:theme= "@style/apptheme" >
< p="">

Three, a key to jump

Add Intent-filter (typically mainactivity) to the Activity tab of the Androidmainfest wake-up page, configure scheme for pull-up in the browser.

<activity
Android:name= ". Mainactivity "
Android:launchmode= "Singletask" >
<intent-filter>
<action android:name= "Android.intent.action.VIEW"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<category android:name= "Android.intent.category.BROWSABLE"/>
<data android:scheme= "afap0343"/>
</intent-filter>
</activity>

Note: If the wake-up page and the startup page are the same activity, the Androidmaifest.xml is configured as follows.

<activity
Android:name= ". Mainactivity "
Android:launchmode= "Singletask" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name= "Android.intent.action.VIEW"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<category android:name= "Android.intent.category.BROWSABLE"/>
<data android:scheme= "afap0343"/>
</intent-filter>
</activity>

Both Personalization and one-click Wakeup Call the same method Shareinstall.getinstance (). GetInfo () Gets the relevant information, the first parameter is intent (note: Intent can be passed null, but the page configured for scheme wake must be passed, Otherwise it will not get the parameters passed in), the second parameter is the information callback listener.

Iv.. Personalized Installation

When the app needs to personalize the installation parameters (which are passed from the Web page, such as the invitation code, the game room number, etc.), call the following method to get the parameters in the callback.

Shareinstall.getinstance (). GetInfo (Intent, New Appgetinfolistener () {br/> @Override

LOG.D ("Shareinstall", "info =" + info);
}
});

V. Wake-up page for information

public class Wakeupactivity extends Appcompatactivity {

@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_wake_up);    // 获取唤醒参数    ShareInstall.getInstance().getInfo(getIntent(), listener);}@Overrideprotected void onNewIntent(Intent intent) {    super.onNewIntent(intent);    // 此处要调用,否则app在后台运行时,会无法截获    ShareInstall.getInstance().getInfo(intent, listener);}private AppGetInfoListener listener = new AppGetInfoListener() {    @Override    public void onGetInfoFinish(String info) {        Log.d("ShareInstall", "info = " + info);    }};

Shareinstall's Android SDK integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.