Introduction
...
Info | |||||||
---|---|---|---|---|---|---|---|
| |||||||
If you choose to use Google Play Services, you need to know the following :
|
...
- Your MainActivity needs to exted AppoxeeBaseActivity and implement AppoxeeObserver
- Your MainActivity onCreate() method should contain :
new initAsync(getApplicationContext(),"APP_KEY",
"SECRET_KEY", "com.package.MainActivity" , true, this).execute();AppoxeeManager.setDebug(true);
Appoxee.parseExtraFields(getIntent().getExtras());
setContentView(R.layout.main);
.....
Make sure that the following methods are implemented and contain Appoxee's method calls :
@Override
protected void onResume()
{
super.onResume();
// If Inbox implemented and you have a method for updating your inbox’s
// Badge
updateMsgBadge();
}
d. @Override
public void onRegistrationCompleted() {
// TODO Auto-generated method stub
Utils.Debug("Can perform all API Calls");
}
@Override
public void onMessagesUpdateCompleted() {
// If Inbox implemented and you have a method for updating your inbox’s
// Badge
Utils.Debug("Can update Badge");
updateMsgBadge();
}
Note To fully use Appoxee’s Analytics , all of your activities should implement onStart() & onStop in the actvities code :
@Override
protected void onStart()
{
super.onStart();
Appoxee.onStart();
}
@Override
protected void onStop()
{
super.onStop();
Appoxee.onStop();
}
In order to avoid these additions in each activity, you can simply extend AppoxeeBaseActivity instead of Activity. (AppoxeeBaseActivity extends Android’s FragmentActivity and contains the onStart() & onStop() calls)
Option B: Implicit Integration (without using Observer)
In your main activity class onCreate() method enter the following code :
new initAsync(getApplicationContext(),"APP_KEY",
"SECRET_KEY", true, "com.package.MainActivity").execute();AppoxeeManager.setDebug(true);
Appoxee.parseExtraFields(getIntent().getExtras());
setContentView(R.layout.main);
.....
- Make sure that the following methods are implemented and contain Appoxee's method calls :
@Override protected void onStart() {
super.onStart();
Appoxee.onStart();
}
@Override
protected void onStop()
{
super.onStop();
Appoxee.onStop();
}
@Overrideprotected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Bundle bundle = intent.getExtras();
Appoxee.parseExtraFields(bundle);
}
@Override
protected void onResume()
{
super.onResume();
// If Inbox implemented and you have a method for updating your inbox’s
// Badge
updateMsgBadge();
}
Note When Integrating Appoxee and choosing not to use an Observer, All Appoxee API Calls will fail unless implementing a thread that will sample the flag
Appoxee.isReady()==true. Only then will the API Calls will execute (Tags,Alias... )
If prompted with an error, add this "Import" command to enable Appoxee SDK usage:
import com.appoxee.Appoxee - AndroidManifest.xml Updates - Make the following changes to your app's AndroidManifest.xml file:
- GCM requires Android 2.2 or later. If your app cannot work without GCM, add the following line, where "xx" is the
Note To fully use Appoxee’s Analytics , all of your activities should implement onStart() & onStop in the actvities code :
Code Block language java linenumbers true @Override protected void onStart() { super.onStart(); Appoxee.onStart(); } @Override protected void onStop() { super.onStop(); Appoxee.onStop(); }
@Override
protected void onStart()
{
super.onStart();
Appoxee.onStart();
}
@Override
protected void onStop()
{
super.onStop();
Appoxee.onStop();
}
In order to avoid these additions in each activity, you can simply extend AppoxeeBaseActivity instead of Activity. (AppoxeeBaseActivity extends Android’s FragmentActivity and contains the onStart() & onStop() calls)
- GCM requires Android 2.2 or later. If your app cannot work without GCM, add the following line, where "xx" is the
Manifest Integration and Advanced Options (Inbox / DeepLink (URLScheme) ) :
In order to avoid these additions in each activity, you can simply extend AppoxeeBaseActivity instead of Activity. (AppoxeeBaseActivity extends Android’s FragmentActivity and contains the onStart() & onStop() calls)
Manifest Integration and Advanced Options (Inbox / DeepLink (URLScheme) ) :
If prompted with an error, add this "Import" command to enable Appoxee SDK usage:
import com.appoxee.Appoxee AndroidManifest.xml Updates - Make the following changes to your app's AndroidManifest.xml file:
GCM requires Android 2.2 or later. If your app cannot work without GCM, add the following line, where "xx" is the latest target SDK version:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="xx" /> Note If your application is intended for android version 4.1 or above (that is, minSdkVersion 16), the next step (2.b.) is not required.
In this case, please skip the next step and proceed to step 2.c.Declare and use a custom permission, so only this application can receive GCM messages:
<permission android:name="com.appoxee.example.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.appoxee.example.permission.C2D_MESSAGE" />Note You must replace "com.appoxee.example" with your app's package name, as defined by the manifest tag, otherwise it will not work.
To allow your app to use Google's Push Notification Service (GCM), add the following permissions:
<!-- This app has permission to register and receive message -->
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />In the manifest file's Application element, make sure your app has the name it has in your class file:
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowClearUserData="true"
android:enabled="true" android:name="MyApplication"/>
The class that extends "Application" that is the name that needs to be in the "MyApplication".
Example:If the package name is "com.david.coolapps" and the class that extends Application is named "MyApp"
then in the Application tag the "name" value is : "com.david.coolapps.MyApp" .
<application
android:name="com.david.coolapps.MyApp"
..... >Add the following child element to your Application element (remember you must replace "com.appoxee.example" with your app's package name, as defined by the manifest tag):
<service android:name="com.appoxee.gcm.GCMIntentService"/>
<receiver android:name="com.appoxee.gcm.GCMBroadcastReceiver"android:permission="com.google.android.c2dm.permission.SEND"></receiver> <!-- Must have for Push Support by Appoxee --> <activity android:name ="com.appoxee.InboxMessage"/>
<!-- Receive the actual message -->
<intent-filter><action android:name="com.google.android.c2dm.intent.RECEIVE" /></intent-filter>
<category android:name="com.appoxee.example" />
<!-- Receive the registration id -->
<intent-filter><action android:name="com.google.android.c2dm.intent.REGISTRATION" /></intent-filter>
<category android:name="com.appoxee.example" />Note If you are using Appoxee's SDK as a "Push Only" solution (without using the Inbox that enables Rich Messages), this completes the integration procedure within the AndroidManifest.xml file.
Please continue to step 5 to complete the rest of the integration by adding your java codeTo enable Appoxee's in-app inbox, and other advanced features, add the following code inside your Application element:
<activity android:name="com.appoxee.activities.Inbox"/>
<activity android:name="com.appoxee.activities.MoreApps"/>
<activity android:name="com.appoxee.activities.Feedback"/> <!-- Add if missing from Push Integration -->
<activity android:name ="com.appoxee.activities.InboxMessage"/>
Your updated AndroidManifest.xml file should be similar to the following example XML: <?xml version="1.0" encoding="utf-8"?>Note The Inbox feature guarantees your ability to engage the user with rich messages (note that the Inbox cannot be disabled by users, as opposed to Push Notifications) and gives you the option to access features such as Feedback and More Apps . The Inbox must be used in your application's code in order to show it and utilize its features. The InboxMessage activity needs to be added in order to support Push Notifications by Appoxee. Check your Manifest.xml and see that it is added below the Receiver declaration.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<!-- REQUIRED -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- REQUIRED for GCM -->
<!-- Only this application can receive the messages and registration result -->
<permission android:name="com.appoxee.example.permission.C2D_MESSAGE"android:protectionLevel="signature" />
<uses-permission android:name="com.appoxee.example.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive message -->
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permissionit is added below the Receiver declaration.
This is the AndroidManifest.xml Code Block for GCM :Code Block language xml title AndroidManifest.xml - GCM Integration linenumbers true <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appoxee.example" android:versionCode="25" android:versionName="2.2" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="23" /> <!-- REQUIRED --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- REQUIRED for C2DM --> <!-- Only this application can receive the messages and registration result --> <permission android:name="com.appoxee.example.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.appoxee.example.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive message --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:name="com.appoxee.example.AppoxeeExample" android:allowBackup="true" android:allowClearUserData="true" android:enabled="true" android:hardwareAccelerated="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:launchMode="singleTask" > <activity android:name="com.appoxee.example.AppoxeeExampleActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- REQUIRED for C2DM --> <service android:name="com.appoxee.gcm.GCMIntentService"> </service> <receiver android:name="com.appoxee.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <!-- Receive the actual message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.appoxee.example" /> </intent-filter> <!-- Receive the registration id --> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.appoxee.example" /> </intent-filter> </receiver> <!-- OPTIONAL, if you want to receive push, push opened and registration completed intents --> <activity android:name="com.appoxee.activities.Inbox" > </activity> <activity android:name="com.appoxee.activities.SplashScreen" > </activity> <activity android:name="com.appoxee.activities.MoreApps" > </activity> <activity android:name="com.appoxee.activities.Feedback" > </activity> <activity android:name="com.appoxee.activities.InboxMessage" > </activity> </application> </manifest>
This is the AndroidManifest.xml Code Block for Google Play Services :
INTERNET" />Code Block theme Eclipse language xml title AndroidManifest - PlayServices Integration linenumbers true <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appoxee.example" android:versionCode="25" android:versionName="2.2" > <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" /> <!-- REQUIRED --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- REQUIRED for C2DM --> <!-- Only this application can receive the messages and registration result --> <permission android:name="com.appoxee.example.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.appoxee.example.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive message --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.
<!-- GCM requires a Google account. -->
<uses-permission
androidACCESS_NETWORK_STATE" /> <application android:name="
permission.GET_ACCOUNTS" />com.appoxee.
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!—The name of MyApplication Needs to be replaced with the name of the class of your application -->
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowClearUserData="true"
android:enabled="true" android:name="MyApplication"/>
<activity android:name="DemoActivity"
/>example.AppoxeeExample" android:allowBackup="true" android:allowClearUserData="true" android:enabled="true" android:hardwareAccelerated="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:launchMode="singleTask" > <!-- This app uses GooglePlayServices.jar --> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.appoxee.example.AppoxeeExampleActivity" android:label="@string/app_name"
<intent-filter><action
/>> <intent-filter> <action android:name="android.intent.action.MAIN"
<category/> <category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
GCM<!-- REQUIRED for
C2DM -->
<service
gcm<service android:name="com.appoxee.gcm.PlayIntentService" > </service> <receiver android:name="com.appoxee.
GCMIntentServicelisteners.
/>OnCoppaReciever"
<receiver
GCMBroadcastReceiver"/> <receiver android:name="com.appoxee.gcm.
>PlayBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"
message -->> <!-- Receive the actual
<intent-filter><action
/>message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"
<category/> <category android:name="com.appoxee.example"
/>
filter></intent-
filter> <!-- Receive the registration id -->
<action<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"
/>
<category
/><category android:name="com.appoxee.example"
/> </intent-filter>
</receiver>
Add the following intents to your application if Inbox and other advanced features are enabled --><!--
<activity
>OPTIONAL, if you want to receive push, push opened and registration completed intents --> <activity android:name="com.appoxee.activities.Inbox" > </
<activity
.activities.MoreApps"/>activity> <activity android:name="com.appoxee.activities.SplashScreen" > </activity> <activity android:name="com.appoxee
<activity
/>.activities.MoreApps" > </activity> <activity android:name="com.appoxee.activities.Feedback"
<activity> </activity> <activity android:name
/>="com.appoxee.activities.InboxMessage"
> </activity> </application>
</manifest>
This completes the AndroidManifest.xml file updates. The remaining updates are made in your app code.
Inbox integration - after enabling the Inbox in your Appoxee account (by going to the app's Application Information page and checking Allow Inbox + Rich messages), add the Inbox to your code as follows:
Add code that opens the Inbox - the Inbox can be opened from any activity. In the example code below, the Inbox is opened from the main activity layout, using the "openInbox():" function:
public void openInbox(View view){Intent intent = new Intent(this, Inbox.class);}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(intent);Add a button that opens the Inbox - it is recommended to add a button to open the Inbox. This button is added in the activity layout as follows:
<Button
android:id="@+id/open_inbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="openInbox"
android:text="Open Appoxee Inbox" />Show the number of unread messages - to show the user the number of unread messages, fetch this number using the following command:
Appoxee.getUnreadMessages();
Depp Link / URL Scheme in Appoxee&Android
Add to your AndroidManifest.xml
<activity android:name="com.appoxee.example.DeepLinkActivity" >
<!-- Add the Intent Filter for activity needed to be URLScheme compatible -->
<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="example" />
</intent-filter>
</activity>
Create DeepLinkActivity.java
//This sample extends AppoxeeBaseActivity, for onStart() & onStop() integration and analytics
public class DeepLinkActivity extends AppoxeeBaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent == null || intent.getData() == null) {
finish();
}
openDeepLink(intent.getData());
// Finish this activity
finish();
}
public void openDeepLink(Uri deepLink) {
String path = deepLink.getPath();
Utils.Debug("Base path: " + path);
//Implement your Code here
path = path.replace("/", "");
Intent intent = new Intent();
intent.setClassName(this, path);
this.startActivity(intent);
} .....
...