下面列出了android.content.Intent#getAction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
context = LocaleManager.setLocale(context);
this.context = context;
savedData = new SavedData(context);
myDatabase = new MyDatabase(context);
hijriSpecialDay = new HijriSpecialDays();
if (intent.getAction() != null && context != null) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// Set the alarm here.
Log.d(TAG, "onReceive: BOOT_COMPLETED");
SavedData savedData = new SavedData(context);
NotificationScheduler.setReminder(context, AlarmReceiver.class, savedData.getAppStartHour(), savedData.getAppStartMin(),savedData.getNewRemainderInterval());
return;
}
}
NotificationScheduler.showNotification(context, MainActivity.class,
context.getString(R.string.app_sub_name), getAtkhar());
}
@Override
public void onReceive(Context context, Intent intent) {
// Handle bookmark-specific updates ourselves because they might be
// coming in without extras, which AppWidgetProvider then blocks.
final String action = intent.getAction();
if (getBookmarkAppWidgetUpdateAction(context).equals(action)) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
performUpdate(context, appWidgetManager,
new int[] {IntentUtils.safeGetIntExtra(intent,
AppWidgetManager.EXTRA_APPWIDGET_ID, -1)});
} else {
performUpdate(context, appWidgetManager,
appWidgetManager.getAppWidgetIds(getComponentName(context)));
}
} else {
super.onReceive(context, intent);
}
}
public void onReceivedBeacon(final Intent intent) {
if (BuildConfig.DEBUG) {
Log.i(TAG, "@@ LinkingBeaconManager#onReceivedBeacon");
Log.i(TAG, "intent=" + intent);
}
if (intent == null) {
return;
}
String action = intent.getAction();
if (LinkingBeaconUtil.ACTION_BEACON_SCAN_RESULT.equals(action)) {
parseBeaconResult(intent);
} else if (LinkingBeaconUtil.ACTION_BEACON_SCAN_STATE.equals(action)) {
parseBeaconScanState(intent);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
Log.i(TAG, "no intent");
return START_NOT_STICKY;
}
String action = intent.getAction();
if (action == null) {
Log.i(TAG, "no action");
return START_NOT_STICKY;
}
Bundle b = intent.getExtras();
if (b != null) {
if (b.getBoolean("service", false)) {
stopSelf();
}
}
connectMiBand();
return START_STICKY;
}
/**
* Get the URI of the selected image from {@link #getPickImageChooserIntent()}.<br/>
* Will return the correct URI for camera and gallery image.
*
* @param data the returned data of the activity result
*/
public Uri getPickImageResultUri(Intent data) {
boolean isCamera = true;
if (data != null) {
if (data.getData() == null)
return getCaptureImageOutputUri();
else {
String action = data.getAction();
isCamera = action != null && action.equals(MediaStore.ACTION_IMAGE_CAPTURE);
return isCamera ? getCaptureImageOutputUri() : data.getData();
}
}
else
return getCaptureImageOutputUri();
}
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_BATTERY_CHANGED)) {
if (mBattery == null)
return;
int batteryLevel = intent.getIntExtra("level", 0);
if (batteryLevel >= 50)
mBattery.setTextColor(Color.GREEN);
else if (batteryLevel >= 30)
mBattery.setTextColor(Color.YELLOW);
else
mBattery.setTextColor(Color.RED);
mBattery.setText(String.format("%d%%", batteryLevel));
}
else if (action.equalsIgnoreCase(VLCApplication.SLEEP_INTENT)) {
exitOK();
}
}
void initializeNfcStateChangeListener() {
nfcStateChangeBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF);
switch (state) {
case NfcAdapter.STATE_OFF:
case NfcAdapter.STATE_TURNING_OFF:
onNfcDisabled();
break;
case NfcAdapter.STATE_TURNING_ON:
break;
case NfcAdapter.STATE_ON:
onNfcEnabled();
break;
}
}
}
};
}
/**
* 重置恢复Intent中的Action
*/
public static void resetAction(Intent intent) {
if (intent == null) {
return;
}
String action = intent.getAction();
if (!TextUtils.isEmpty(action) && action.contains(TOKEN)) {
String[] info = action.split(TOKEN);
if (info != null && info.length == 2) {
action = info[1];
}
}
PluginDebugLog.log(TAG, "resetAction: " + action);
if (TextUtils.isEmpty(action) || action.equalsIgnoreCase("null")) {
action = null;
}
intent.setAction(action);
}
@Override
public void onReceive(Context context, Intent intent) {
TalkBackService service = TalkBackService.getInstance();
if (service == null) {
return;
}
EventId eventId = EVENT_ID_UNTRACKED; // Not a user-initiated event.
// We need to ensure that onLockedBootCompleted() and onUnlockedBootCompleted() are called
// *in that order* to properly set up TalkBack.
switch (intent.getAction()) {
case Intent.ACTION_LOCKED_BOOT_COMPLETED:
// Only N+ devices will get this intent (even if they don't have FBE enabled).
service.onLockedBootCompleted(eventId);
break;
case Intent.ACTION_BOOT_COMPLETED:
if (!BuildVersionUtils.isAtLeastN()) {
// Pre-N devices will never get LOCKED_BOOT, so we need to do the locked-boot
// initialization here right before we do the unlocked-boot initialization.
service.onLockedBootCompleted(eventId);
}
service.onUnlockedBootCompleted();
break;
default: // fall out
}
}
@Override
public void onReceive(final Context context, @NonNull final Intent intent) {
final String action = intent.getAction();
AbsMusicServiceActivity activity = reference.get();
if (activity != null) {
switch (action) {
case MusicService.META_CHANGED:
activity.onPlayingMetaChanged();
break;
case MusicService.QUEUE_CHANGED:
activity.onQueueChanged();
break;
case MusicService.PLAY_STATE_CHANGED:
activity.onPlayStateChanged();
break;
case MusicService.REPEAT_MODE_CHANGED:
activity.onRepeatModeChanged();
break;
case MusicService.SHUFFLE_MODE_CHANGED:
activity.onShuffleModeChanged();
break;
case MusicService.MEDIA_STORE_CHANGED:
activity.onMediaStoreChanged();
break;
}
}
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case Trigger.DEBUG_DEVICE_ON_B:
if (!Trigger.DEBUG)
break;
case Intent.ACTION_BOOT_COMPLETED:
context.startService(TriggerLoop.deviceOn(context));
break;
default:
break;
}
}
@Override
public void onReceive(Context context, Intent intent) {
String action=intent.getAction();
if(NEWSFRAGMENT_TYPE_ACTION.equals(action)){
type=intent.getIntExtra(NEWSFRAGMENT_TYPE_ACTION,2);
refresh();
}
}
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
Intent intent = (Intent) args[1];
String type = (String) args[2];
intent.setDataAndType(redirectData(intent.getData()), type);
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) && intent.getData() != null) {
ContentValues values = new ContentValues(2);
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(intent.getDataString()));
values.put("mime_type", mime);
values.put("_data", intent.getData().getPath());
VLog.d(getName(), "try " + values);
if (mime.startsWith("image"))
VirtualCore.get().getContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
else if (mime.startsWith("video"))
VirtualCore.get().getContext().getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
else if (mime.startsWith("audio"))
VirtualCore.get().getContext().getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
}
if (VirtualCore.get().getComponentDelegate() != null) {
if (!VirtualCore.get().getComponentDelegate().onSendBroadcast(intent)) return null;
}
Intent newIntent = handleIntent(intent);
if (newIntent != null) {
args[1] = newIntent;
} else {
return 0;
}
if (args[7] instanceof String || args[7] instanceof String[]) {
// clear the permission
args[7] = null;
}
VLog.d(getName(), "broadcast " + intent);
return method.invoke(who, args);
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
if (state == BluetoothAdapter.STATE_ON ){
addFooterView();
getManager().startScanBle();
} else if (state == BluetoothAdapter.STATE_OFF) {
addFooterView();
getManager().stopScanBle();
}
}
}
private void handleIntent( Intent intent ) {
if( intent == null || intent.getAction() == null || mCallbacks == null) {
return;
}
String action = intent.getAction();
if( action.equalsIgnoreCase( ACTION_PLAY ) ) {
mCallbacks.onPlay();
} else if( action.equalsIgnoreCase( ACTION_PAUSE ) ) {
mCallbacks.onPause();
} else if( action.equalsIgnoreCase( ACTION_FORWARD) ) {
mCallbacks.onFastForward();
} else if( action.equalsIgnoreCase( ACTION_REWIND ) ) {
mCallbacks.onRewind();
} else if( action.equalsIgnoreCase( ACTION_PREVIOUS ) ) {
mCallbacks.onSkipToPrevious();
} else if( action.equalsIgnoreCase( ACTION_NEXT ) ) {
mCallbacks.onSkipToNext();
} else if( action.equalsIgnoreCase( ACTION_STOP ) ) {
mCallbacks.onStop();
} else if( action.equalsIgnoreCase( ACTION_SEEK ) && intent.hasExtra( VOD_PROGRESS ) ) {
if (mp != null && mediaSession.isActive()) {
mp.seekTo(intent.getIntExtra( VOD_PROGRESS, 0 ));
}
}
}
private void onInit() {
Intent intent = getIntent();
if (intent == null) {
return;
}
mAction = intent.getAction();
mFilename = intent.getStringExtra(KEY_FILENAME);
mUri = intent.getData();
mGalleryInfo = intent.getParcelableExtra(KEY_GALLERY_INFO);
mPage = intent.getIntExtra(KEY_PAGE, -1);
buildProvider();
}
/**
* Start running background data collection methods.
*
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
log("cbservice onstartcommand");
checkBarometer();
loadConditionsNotificationPref();
// wakelock management
if(wl!=null) {
log("cbservice wakelock not null:");
if(wl.isHeld()) {
log("cbservice existing wakelock; releasing");
wl.release();
} else {
log("cbservice wakelock not null but no existing lock");
}
}
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP , "CbService"); // PARTIAL_WAKE_LOCK
wl.acquire(1000);
log("cbservice acquiring wakelock " + wl.isHeld());
dataCollector = new CbDataCollector();
try {
if (intent != null) {
if (intent.getAction() != null) {
if (intent.getAction().equals(ACTION_SEND_MEASUREMENT)) {
// send just a single measurement
fromUser = false;
log("sending single observation, request from intent");
sendSingleObs();
return START_NOT_STICKY;
} else if (intent.getAction().equals(ACTION_SEND_MEASUREMENT_WITH_LOCATION)) {
if(intent.hasExtra("latitude")) {
fromUser = false;
log("sending single observation, request from intent");
Location thisLocation = new Location("network");
double latitude = intent.getDoubleExtra("latitude", 0.0);
double longitude = intent.getDoubleExtra("longitude", 0.0);
thisLocation.setLatitude(latitude);
thisLocation.setLongitude(longitude);
sendSingleObs(thisLocation);
}
return START_NOT_STICKY;
}
} else if (intent.getBooleanExtra("alarm", false)) {
// This runs when the service is started from the alarm.
// Submit a data point
log("cbservice alarm firing, sending data");
settingsHandler = new CbSettingsHandler(getApplicationContext());
settingsHandler = settingsHandler.getSettings();
removeOldSDKApps();
sendRegistrationInfo();
if(settingsHandler.isSharingData()) {
//dataCollector.startCollectingData();
startWithIntent(intent, true);
} else {
log("cbservice not sharing data");
}
LocationStopper stop = new LocationStopper();
mHandler.postDelayed(stop, 1000 * 3);
return START_NOT_STICKY;
} else {
// Check the database
log("cbservice on boot registering for notifications");
registerForNotifications();
log("starting service with db");
startWithDatabase();
return START_NOT_STICKY;
}
}
} catch (Exception e) {
log("cbservice onstartcommand exception " + e.getMessage());
}
super.onStartCommand(intent, flags, startId);
return START_NOT_STICKY;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// We won't create a new thread because the request to the host are
// already done in a separate thread. Just fire the request and forget
HostConnection hostConnection = HostManager.getInstance(this).getConnection();
String action = intent.getAction();
int playerId = intent.getIntExtra(EXTRA_PLAYER_ID, -1);
if ((hostConnection != null) && (playerId != -1)) {
switch (action) {
case ACTION_PLAY_PAUSE:
hostConnection.execute(
new Player.PlayPause(playerId),
null, null);
break;
case ACTION_REWIND:
hostConnection.execute(
new Player.SetSpeed(playerId, GlobalType.IncrementDecrement.DECREMENT),
null, null);
break;
case ACTION_FAST_FORWARD:
hostConnection.execute(
new Player.SetSpeed(playerId, GlobalType.IncrementDecrement.INCREMENT),
null, null);
break;
case ACTION_PREVIOUS:
hostConnection.execute(
new Player.GoTo(playerId, Player.GoTo.PREVIOUS),
null, null);
break;
case ACTION_NEXT:
hostConnection.execute(
new Player.GoTo(playerId, Player.GoTo.NEXT),
null, null);
break;
case ACTION_JUMP_BACKWARD:
hostConnection.execute(
new Player.Seek(playerId, Player.Seek.BACKWARD),
null, null);
break;
case ACTION_JUMP_FORWARD:
hostConnection.execute(
new Player.Seek(playerId, Player.Seek.FORWARD),
null, null);
break;
}
}
return START_NOT_STICKY;
}
@SuppressWarnings("unchecked")
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case AppCast.ASSET_DOWNLOAD_REQUEST.ACTION: {
switch (intent.getIntExtra(AppCast.ASSET_DOWNLOAD_REQUEST.EXTRA_RESULT, AssetUpdater.UpdateThread.ASSET_DOWNLOAD_REQUEST__FAILED)) {
case AssetUpdater.UpdateThread.ASSET_DOWNLOAD_REQUEST__CHECKING: {
updateInfoBar(0, R.string.download_latest_assets_checking_description, R.drawable.ic_file_download_white_32dp, false);
break;
}
case AssetUpdater.UpdateThread.ASSET_DOWNLOAD_REQUEST__FAILED: {
updateInfoBar(0, R.string.downloading_failed, R.drawable.ic_file_download_white_32dp, false);
break;
}
case AssetUpdater.UpdateThread.ASSET_DOWNLOAD_REQUEST__DO_DOWNLOAD_ASK: {
updateInfoBar(0, R.string.download_latest_assets_checking_description, R.drawable.ic_file_download_white_32dp, false);
showDownloadDialog();
break;
}
}
return;
}
case AppCast.DOWNLOAD_STATUS.ACTION: {
int percent = intent.getIntExtra(AppCast.DOWNLOAD_STATUS.EXTRA_PERCENT, 100);
switch (intent.getIntExtra(AppCast.DOWNLOAD_STATUS.EXTRA_STATUS, AssetUpdater.UpdateThread.DOWNLOAD_STATUS__FAILED)) {
case AssetUpdater.UpdateThread.DOWNLOAD_STATUS__DOWNLOADING: {
updateInfoBar(percent, R.string.downloading, R.drawable.ic_file_download_white_32dp, true);
break;
}
case AssetUpdater.UpdateThread.DOWNLOAD_STATUS__FAILED: {
updateInfoBar(percent, R.string.downloading_failed, R.drawable.ic_mood_bad_black_256dp, false);
break;
}
case AssetUpdater.UpdateThread.DOWNLOAD_STATUS__UNZIPPING: {
updateInfoBar(percent, R.string.unzipping, R.drawable.ic_file_download_white_32dp, true);
break;
}
case AssetUpdater.UpdateThread.DOWNLOAD_STATUS__FINISHED: {
updateInfoBar(percent, R.string.successfully_downloaded, R.drawable.ic_gavel_white_48px, false);
break;
}
}
return;
}
case AppCast.ASSETS_LOADED.ACTION: {
selectTab(_tabLayout.getSelectedTabPosition(), _currentMainMode);
updateHiddenNavOption();
break;
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.context = getApplicationContext();
mediaSession = new MediaSessionCompat(this.context, "playback");
// ! TODO handle MediaButtonReceiver's callbacks
// MediaButtonReceiver.handleIntent(mediaSession, intent);
// mediaSession.setCallback(mediaSessionCallback);
if (intent.getAction() != null) {
AudioObject currentAudioObject;
if (this.playerMode == PlayerMode.PLAYLIST) {
currentAudioObject = this.audioObjects.get(player.getCurrentWindowIndex());
} else {
currentAudioObject = this.audioObject;
}
if (intent.getAction().equals(MediaNotificationManager.PREVIOUS_ACTION)) {
if (currentAudioObject.getNotificationActionCallbackMode() == NotificationActionCallbackMode.DEFAULT) {
previous();
} else {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.PREVIOUS);
}
} else if (intent.getAction().equals(MediaNotificationManager.PLAY_ACTION)) {
if (currentAudioObject.getNotificationActionCallbackMode() == NotificationActionCallbackMode.DEFAULT) {
if (!stopped) {
resume();
} else {
if (playerMode == PlayerMode.PLAYLIST) {
playAll(audioObjects, 0, 0);
} else {
play(audioObject, 0);
}
}
} else {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.PLAY);
}
} else if (intent.getAction().equals(MediaNotificationManager.PAUSE_ACTION)) {
if (currentAudioObject.getNotificationActionCallbackMode() == NotificationActionCallbackMode.DEFAULT) {
pause();
} else {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.PAUSE);
}
} else if (intent.getAction().equals(MediaNotificationManager.NEXT_ACTION)) {
if (currentAudioObject.getNotificationActionCallbackMode() == NotificationActionCallbackMode.DEFAULT) {
next();
} else {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.NEXT);
}
} else if (intent.getAction().equals(MediaNotificationManager.CUSTOM1_ACTION)) {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.CUSTOM1);
} else if (intent.getAction().equals(MediaNotificationManager.CUSTOM2_ACTION)) {
ref.handleNotificationActionCallback(this.foregroundAudioPlayer, NotificationActionName.CUSTOM2);
}
}
return START_STICKY;
}