本文整理汇总了Java中android.support.v4.content.WakefulBroadcastReceiver类的典型用法代码示例。如果您正苦于以下问题:Java WakefulBroadcastReceiver类的具体用法?Java WakefulBroadcastReceiver怎么用?Java WakefulBroadcastReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WakefulBroadcastReceiver类属于android.support.v4.content包,在下文中一共展示了WakefulBroadcastReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent.getExtras() != null) {
String personId = intent.getStringExtra("person_id");
Realm realm = Realm.getDefaultInstance();
Person person = realm.where(Person.class).equalTo("id", personId).findFirst();
final String output = person.toString();
new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Loaded Person from broadcast-receiver->intent-service: " + output, Toast.LENGTH_LONG).show();
}
});
realm.close();
}
// All the work is done, release the wake locks/etc
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
示例2: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if(intent == null) return;
try {
final String action = intent.getAction();
if(ACTION_CHECK.equals(action)) {
loadNotifications();
} else if(ACTION_DELETE.equals(action) && intent.hasExtra("notification")) {
Editor.getEditor(this).markNotificationThreadRead(
((Notification) intent.getParcelableExtra("notification")).getId()
);
}
} finally {
Logger.i(TAG, "onHandleIntent: " + intent.toString());
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
示例3: onStartCommand
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent"));
enforceCallingPermission(DashClockExtension.PERMISSION_READ_EXTENSION_DATA);
if (intent != null) {
String action = intent.getAction();
if (ACTION_UPDATE_WIDGETS.equals(action)) {
handleUpdateWidgets(intent);
} else if (ACTION_UPDATE_EXTENSIONS.equals(action)) {
handleUpdateExtensions(intent);
}
// If started by a wakeful broadcast receiver, release the wake lock it acquired.
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
return START_STICKY;
}
示例4: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
try {
String action = intent.getAction();
if (ACTION_START.equals(action)) {
Contact contact = intent.getParcelableExtra(EXTRA_CONTACT_NOTIFICATION);
//TODO processStartNotification(contact);
}
if (ACTION_DELETE.equals(action)) {
processDeleteNotification(intent);
}
} finally {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
示例5: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) { // has effect of unparcelling Bundle
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
.equals(messageType)) {
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
.equals(messageType)) {
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
.equals(messageType)) {
if (MyApp.getInstance().isPushEnabled()) {
sendNotification("Received: " + extras.toString());
}
}
}
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
示例6: onStartCommand
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
public int onStartCommand(Intent intent, int flags, int startId) {
synchronized (this) {
this.counter++;
if (startId > this.startId) this.startId = startId;
}
try {
if (intent != null) {
if (ACTION_INSTANCE_ID.equals(intent.getAction()) && intent.hasExtra(EXTRA_GSF_INTENT)) {
startService((Intent) intent.getParcelableExtra(EXTRA_GSF_INTENT));
return START_STICKY;
}
handleIntent(intent);
if (intent.hasExtra(EXTRA_FROM))
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
} finally {
stop();
}
return START_NOT_STICKY;
}
示例7: onStartCommand
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
connectGoogleApiClient();
initLocalVars(intent);
showOngoingNotification();
listenForUpdates();
startCompassActivity();
if(useWatchCompass) {
setupLocationUtils(cacheLocation);
locationUtils.startDirectionalTracking(getApplicationContext());
}
WakefulBroadcastReceiver.completeWakefulIntent(intent);
return START_REDELIVER_INTENT;
}
示例8: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
@Override
protected void onHandleIntent(Intent intent) {
try {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREF_ENABLE_CHECKIN, false)) {
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
if (info != null) {
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
PeopleManager.loadUserInfo(this, account);
}
McsService.scheduleReconnect(this);
if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
}
}
}
} catch (Exception e) {
Log.w(TAG, e);
} finally {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
stopSelf();
}
}
示例9: onStartCommand
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
synchronized (McsService.class) {
if (rootHandler != null) {
if (intent == null) return START_REDELIVER_INTENT;
wakeLock.acquire(WAKELOCK_TIMEOUT);
Object reason = intent.hasExtra(EXTRA_REASON) ? intent.getExtras().get(EXTRA_REASON) : intent;
if (ACTION_CONNECT.equals(intent.getAction())) {
rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, reason));
} else if (ACTION_HEARTBEAT.equals(intent.getAction())) {
rootHandler.sendMessage(rootHandler.obtainMessage(MSG_HEARTBEAT, reason));
} else if (ACTION_SEND.equals(intent.getAction())) {
handleSendMessage(intent);
}
WakefulBroadcastReceiver.completeWakefulIntent(intent);
} else if (connectIntent == null) {
connectIntent = intent;
} else {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
return START_REDELIVER_INTENT;
}
示例10: onStartCommand
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent"));
if (intent != null) {
String action = intent.getAction();
if (ACTION_UPDATE_WIDGETS.equals(action)) {
handleUpdateWidgets(intent);
} else if (ACTION_UPDATE_EXTENSIONS.equals(action)) {
handleUpdateExtensions(intent);
}
// If started by a wakeful broadcast receiver, release the wake lock it acquired.
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
return START_STICKY;
}
示例11: onReceive
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if(prefs.getBoolean(RSSRelatedConstants.NOTIF_KEYS[0], true) && !prefs.getBoolean(MainActivity.FIRST_OPEN, true)) {
RSSScheduledServiceHelper.startScheduled(context);
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
示例12: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.i(TAG, "Sync intent received. Fetching data from network.");
sSunshineSyncEngine.performUpdate();
// Release the wake lock provided by the WakefulBroadcastReceiver.
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
示例13: onReceive
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
// Pass right over to SMSDispatcherIntentService class, the wakeful receiver is
// just needed in case the schedule is triggered while the device
// is asleep otherwise the service may not have time to trigger the
// alarm.
intent.setClass(context, SMSDispatcherIntentService.class);
WakefulBroadcastReceiver.startWakefulService(context, intent);
}
示例14: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
try {
String to = intent.getStringExtra(TO_KEY);
String text = intent.getStringExtra(TEXT_KEY);
Log.i("SMS Dispatcher", "Delivering message to " + text);
SmsManager sms = SmsManager.getDefault();
Intent deliveredIntent = new Intent("sms_delivered");
deliveredIntent.putExtra(SMSDispatcher.TO_KEY, to);
deliveredIntent.putExtra(SMSDispatcher.TEXT_KEY, text);
sms.sendTextMessage(to, null, text, null, null);
} finally {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:16,代码来源:SMSDispatcherIntentService.java
示例15: onHandleIntent
import android.support.v4.content.WakefulBroadcastReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
// Do the task here
Log.i(CosiLoyaltyCardService.class.getName(), "Cosi Service running");
// Release the wake lock provided by the WakefulBroadcastReceiver.
WakefulBroadcastReceiver.completeWakefulIntent(intent);
Device device = Device.registeredDevice();
// cozy register device url
designUrl = device.getUrl() + "/ds-api/request/loyaltycard/all/";
syncUrl = device.getUrl() + "/ds-api/data/";
// concatenate username and password with colon for authentication
final String credentials = device.getLogin() + ":" + device.getPassword();
authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
showNotification();
if (isNetworkAvailable()) {
try {
EventBus.getDefault().post(new LoyaltyCardSyncEvent(SYNC_MESSAGE, "Getting loyalty cards from Cozy..."));
getRemoteLoyaltyCards();
mNotifyManager.cancel(notification_id);
sendChangesToCozy();
EventBus.getDefault().post(new LoyaltyCardSyncEvent(REFRESH, "Sync OK"));
} catch (Exception e) {
e.printStackTrace();
mSyncRunning = false;
EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
}
} else {
mSyncRunning = false;
EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, "No Internet connection"));
mBuilder.setContentText("Sync failed because no Internet connection was available");
mNotifyManager.notify(notification_id, mBuilder.build());
}
}