Cheshmak SDK - Android Studio Demo App
Switch branches/tags
Nothing to show
Clone or download
Latest commit daf9841 Nov 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea edit Nov 8, 2018
app edit Nov 26, 2018
gradle/wrapper update gradle Oct 26, 2018
.gitignore Add Feature version 1.0.29 Jul 30, 2016
README.md Update README.md Mar 7, 2018
build.gradle edit Nov 8, 2018
gradle.properties Initial Commit Apr 19, 2016
gradlew Initial Commit Apr 19, 2016
gradlew.bat Initial Commit Apr 19, 2016
sdk-test.iml Initial Commit Apr 19, 2016
settings.gradle Initial Commit Apr 19, 2016

README.md

android-studio-demo-app

Cheshmak SDK - Android Studio Demo App - Java

This repository shows how to use Cheshmak SDK in a demo application written in android. You may use it to either bootstrap your own project, or as an example to use common features in the Cheshmak SDK. Please feel free to fork this project and make pull requests.

What is Cheshmak ?

Cheshmak is a mobile backend as a service platform offering the following services to mobile app developers free of charge:

  • App Analytics
  • Push Notification
  • Crash Reporting
  • Ad Monetization Please visit our website for further information: https://www.cheshmak.me

Installation

1.Permissions

Insert the following permissions into your AndroidManifest.xml file.

​<uses-permission android:name="android.permission.INTERNET" />​
​<uses-permission android:name="android.permission.VIBRATE" />​
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

The last two permissions are optional and are recommended to increase ad monetization and targeting.

2.Build.gradle

Add the Cheshmak repo to your build.gradle file:

repositories {
 jcenter()
 //Add Maven block to your repositories section
 maven {
 url 'https://repository.cheshmak.me'
 }
}

Next, add the below dependencies to build.gradle file:

compile 'me.cheshmak:analytics:2.+'
compile 'com.google.android.gms:play-services-gcm:10.0.1'

3. Initializing the SDK

Before you can initialize and use the Cheshmak SDK, ensure that you have already configured your app in the Cheshmak panel. You will receive an APP KEY for your app in the panel. When you initialize the SDK, you make it ready for use in your app. It sets initial values and performs other setup tasks. This is required for the features of the Cheshmak SDK to work. First, create an application class (look here if you need assistance) Next, paste the following code snippet into your app's Application class onCreate() method.

        Cheshmak.with(ApplicationClass.this);
        // Replace <YOUR_APP_KEY> below with the real APP KEY that has been provided in the panel
        Cheshmak.initTracker("<YOUR_APP_KEY>"); 

4. Advertisement Display

First, add the below code to your application class:

        // Initialize Advertisement
        CheshmakAds.initiate(getApplicationContext());
        CheshmakAds.enableBannerAds(); // enable banner ads

Second, add the banner view to your xml file where you want to show ads

   <me.cheshmak.android.sdk.advertise.Banner
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   />

for disable showing banner use bellow line code.

CheshmakAds.disableBannerAds();

5. Push notification Handling

To open an activity once a user clicks on a push notification, insert the following snippet into your manifest file:

​<activity
android:name=".YourActivity"​
android:label="your_activity_name">​
​<meta-data android:name="cheshmakPush" android:value="openActivityOnPush"/>​
​</activity>

6. Receiving Data through Push Notification

for receive data from push you can get data in the following way.

​​​
​protected void onCreate(Bundle savedInstanceState) {
  //some code​
  Intent intent = getIntent();
  if (intent != null) {
   if (intent.getExtras() != null) {
    Toast.makeText(this,"Cheshmak push notification data"+​
    intent.getExtras().getString("me.cheshmak.data")+"\n"+​
    intent.getExtras().getString("title")+"\n"+​
    intent.getExtras().getString("message")+"\n",Toast.LENGTH_SHORT).show();
   }
  }
  //some code​
}
 

7. Using Push to Open Services

You may use push notifications to send instructions to the device to start a service. Please see below as an example:

​
​<service android:name=".MyService">​
<meta-data android:name="cheshmakPush"​
android:value="startServiceOnPush" />​
​</service>​
 
@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        try {
            Log.d("CHESHMAK_POPP", "SERVICE STARTED" + intent.getStringExtra("me.cheshmak.data"));

            //get json Data that you set in cheshmak panel
            JSONObject object = new JSONObject(intent.getStringExtra("me.cheshmak.data"));
            String myOption = object.getString("MyKey");

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return START_NOT_STICKY;
    }
 

8. Tagging

You may tag a user by using the following code:

Cheshmak.sendTag("premiumUser");
List tags = new ArrayList<String>();
tags.add("premiumUser");
tags.add("tagA");
tags.add("tagB");
Cheshmak.sendTags(tags);

Remove a tag:

Cheshmak.deleteTag("premiumUser");
List tags = new ArrayList<String>();
tags.add("premiumUser");
tags.add("tagA");
tags.add("tagB");
Cheshmak.deleteTags(tags);

Remove all tages:

Cheshmak.deleteAllTags();

9. Exception Handling:

send exceptions:

try{
 //Do some buggy things​
 }
​catch (Exception ex) {
 Cheshmak.trackException("Image-resize-error", ex);
}
 

send exception with high priority:

try{
 //Do some buggy things​
}
​catch (Exception ex){
 Cheshmak.trackException("memory-exception-error",ex,true);
}
 

Send exception without a title:

try{
 //Do some buggy things​
 }
​catch (Exception ex) {
 Cheshmak.trackException(ex);
}
 

Please visit the Documentation page for further details on the Cheshmak features.