Skip to content

Commit 41246d1

Browse files
1) giving support for 4.4.0 and above version
1 parent e5d6ce1 commit 41246d1

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

app/src/main/AndroidManifest.xml

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
</intent-filter>
3838
</service>
3939

40+
<receiver android:name="com.onefeedsdk.receiver.CommonReceiver"
41+
android:enabled="true"
42+
android:exported="true">
43+
<intent-filter>
44+
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
45+
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
46+
<action android:name="android.intent.action.HEADSET_PLUG"/>
47+
<action android:name="android.intent.action.USER_PRESENT"/>
48+
</intent-filter>
49+
50+
</receiver>
51+
4052
<meta-data android:name="com.onefeed.sdk.ApiKey"
4153
android:value="@string/onefeed_api_key"/>
4254

onefeedsdk/src/main/java/com/onefeedsdk/app/OneFeedSdk.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.onefeedsdk.job.PostUserTrackingJob;
2222
import com.onefeedsdk.listener.AddResponseListener;
2323
import com.onefeedsdk.listener.CallBackListener;
24+
import com.onefeedsdk.receiver.CommonReceiver;
2425
import com.onefeedsdk.service.CommonJobService;
2526
import com.onefeedsdk.rest.ApiFactory;
2627
import com.onefeedsdk.service.CommonService;
@@ -263,10 +264,15 @@ private void initializeSdk(){
263264
}
264265

265266
private void startService() {
266-
try {
267-
context.startService(new Intent(context, CommonService.class));
268-
}catch (Exception e){
269-
Log.e("Exception", e.getMessage());
267+
268+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
269+
try {
270+
context.startService(new Intent(context, CommonService.class));
271+
} catch (Exception e) {
272+
Log.e("Exception", e.getMessage());
273+
}
274+
}else {
275+
context.sendBroadcast(new Intent(context, CommonReceiver.class));
270276
}
271277
}
272278

onefeedsdk/src/main/java/com/onefeedsdk/service/CommonService.java

+18-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.support.annotation.RequiresApi;
1515
import android.util.Log;
1616

17+
import com.onefeedsdk.receiver.CommonReceiver;
18+
1719
/**
1820
* Created by Yogesh Soni.
1921
* Company: WittyFeed
@@ -54,23 +56,26 @@ public void onDestroy() {
5456
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
5557
@Override
5658
public int onStartCommand(Intent intent, int flags, int startId) {
57-
Log.e("onStartCommand", "onStartCommand");
59+
Log.e("onStartCommand", "onStartCommand");
5860
startJobService();
5961
return START_STICKY;
6062
}
6163

62-
@TargetApi(Build.VERSION_CODES.M)
63-
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
64-
private void startJobService(){
65-
66-
JobScheduler js = (JobScheduler) this.getSystemService(
67-
Context.JOB_SCHEDULER_SERVICE);
68-
JobInfo job = new JobInfo.Builder(
69-
0, new ComponentName(this, CommonJobService.class))
70-
.setRequiresCharging(true)
71-
.setOverrideDeadline(1)
72-
.build();
73-
js.schedule(job);
64+
65+
private void startJobService() {
66+
67+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
68+
JobScheduler js = (JobScheduler) this.getSystemService(
69+
Context.JOB_SCHEDULER_SERVICE);
70+
71+
JobInfo job = new JobInfo.Builder(
72+
0, new ComponentName(this, CommonJobService.class))
73+
.setRequiresCharging(true)
74+
.setOverrideDeadline(1)
75+
.build();
76+
js.schedule(job);
77+
}else{
78+
}
7479

7580

7681
/* ComponentName serviceComponent = new ComponentName(this, CommonJobService.class);

0 commit comments

Comments
 (0)