Java Code Examples for android.app.PendingIntent#FLAG_UPDATE_CURRENT

The following examples show how to use android.app.PendingIntent#FLAG_UPDATE_CURRENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing15_8() {
  if (
    ActivityCompat
      .checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED ||
      ActivityCompat
        .checkSelfPermission(this, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED) {

    // Listing 15-8: Requesting location updates using a Pending Intent
    FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    LocationRequest request = new LocationRequest()
                                .setInterval(60000 * 10) // Update every 10 minutes.
                                .setPriority(LocationRequest.PRIORITY_NO_POWER);

    final int locationUpdateRC = 0;
    int flags = PendingIntent.FLAG_UPDATE_CURRENT;

    Intent intent = new Intent(this, MyLocationUpdateReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, locationUpdateRC, intent, flags);

    fusedLocationClient.requestLocationUpdates(request, pendingIntent);
  }
}
 
Example 2
Source File: HBMWidget.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    int N = appWidgetIds.length;
    for (int i = 0; i < N; i++) {
        int appWidgetId = appWidgetIds[i];
        // Make sure that the widget is in the correct state when widgets are updating.
        doupdate(context, Screen.isScreenHBMActive());

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.hbm_widget_layout);
        Intent intent = new Intent(context, HBMWidget.class);
        intent.setAction("com.kerneladiutor.mod.action.TOGGLE_HBM");
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        int flag = PendingIntent.FLAG_UPDATE_CURRENT;
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, flag);
        views.setOnClickPendingIntent(R.id.imageView, pi);

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
Example 3
Source File: PendingIntentConverter.java    From json2notification with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(PendingIntent pendingIntent, String fieldName, boolean writeFieldNameForObject,
        JsonGenerator jsonGenerator) throws IOException {
    android.util.Log.d("json2notification", "PendingIntentConverter:serialize");
    if (pendingIntent == null) return;
    SimplePendingIntent simplePendingIntent = new SimplePendingIntent();
    simplePendingIntent.requestCode = 0;
    simplePendingIntent.flags = PendingIntent.FLAG_UPDATE_CURRENT;
    //simplePendingIntent.intent = pendingIntent.getIntent(); // hidden-api
    simplePendingIntent.intent = getIntent(pendingIntent);
    // pendingIntent.isActivity(); // hidden-api
    boolean isActivity = isActivity(pendingIntent);
    if (isActivity) {
        simplePendingIntent.getActivity = true;
    } else {
        simplePendingIntent.getService = true;
    }
    if (writeFieldNameForObject) jsonGenerator.writeFieldName(fieldName);
    new SimplePendingIntent$$JsonObjectMapper().serialize((SimplePendingIntent) simplePendingIntent, jsonGenerator, true);
}
 
Example 4
Source File: TextClassification.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a PendingIntent for the specified intent.
 * Returns null if the intent is not supported for the specified context.
 *
 * @throws IllegalArgumentException if context or intent is null
 * @hide
 */
@Nullable
public static PendingIntent createPendingIntent(
        @NonNull final Context context, @NonNull final Intent intent, int requestCode) {
    final int flags = PendingIntent.FLAG_UPDATE_CURRENT;
    switch (getIntentType(intent, context)) {
        case IntentType.ACTIVITY:
            return PendingIntent.getActivity(context, requestCode, intent, flags);
        case IntentType.SERVICE:
            return PendingIntent.getService(context, requestCode, intent, flags);
        default:
            return null;
    }
}
 
Example 5
Source File: NotifyUtil.java    From NotifyUtil with Apache License 2.0 5 votes vote down vote up
public static PendingIntent buildIntent(Class clazz){
    int flags = PendingIntent.FLAG_UPDATE_CURRENT;
    Intent intent = new Intent(NotifyUtil.context, clazz);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(NotifyUtil.context, 0, intent, flags);
    return pi;
}
 
Example 6
Source File: GetIntentSender.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    String creator = (String) args[1];
    args[1] = getHostPkg();
    String[] resolvedTypes = (String[]) args[6];
    int type = (int) args[0];
    if (args[5] instanceof Intent[]) {
        Intent[] intents = (Intent[]) args[5];
        if (intents.length > 0) {
            Intent intent = intents[intents.length - 1];
            if (resolvedTypes != null && resolvedTypes.length > 0) {
                intent.setDataAndType(intent.getData(), resolvedTypes[resolvedTypes.length - 1]);
            }
            Intent proxyIntent = redirectIntentSender(type, creator, intent);
            if (proxyIntent != null) {
                intents[intents.length - 1] = proxyIntent;
            }
        }
    }
    if (args.length > 7 && args[7] instanceof Integer) {
        args[7] = PendingIntent.FLAG_UPDATE_CURRENT;
    }
    IInterface sender = (IInterface) method.invoke(who, args);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && sender != null && creator != null) {
        VActivityManager.get().addPendingIntent(sender.asBinder(), creator);
    }
    return sender;
}
 
Example 7
Source File: JobProxy14.java    From android-job with Apache License 2.0 5 votes vote down vote up
protected int createPendingIntentFlags(boolean repeating) {
    int flags = PendingIntent.FLAG_UPDATE_CURRENT;
    if (!repeating) {
        flags |= PendingIntent.FLAG_ONE_SHOT;
    }
    return flags;
}
 
Example 8
Source File: FirstRunFlowSequencer.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Adds fromIntent as a PendingIntent to the firstRunIntent. This should be used to add a
 * PendingIntent that will be sent when first run is either completed or canceled.
 *
 * @param caller            The context that corresponds to the Intent.
 * @param firstRunIntent    The intent that will be used to start first run.
 * @param fromIntent        The intent that was used to launch Chrome.
 * @param requiresBroadcast Whether or not the fromIntent must be broadcasted.
 */
private static void addPendingIntent(
        Context caller, Intent firstRunIntent, Intent fromIntent, boolean requiresBroadcast) {
    PendingIntent pendingIntent = null;
    int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT;
    if (requiresBroadcast) {
        pendingIntent = PendingIntent.getBroadcast(
                caller, FIRST_RUN_EXPERIENCE_REQUEST_CODE, fromIntent, pendingIntentFlags);
    } else {
        pendingIntent = PendingIntent.getActivity(
                caller, FIRST_RUN_EXPERIENCE_REQUEST_CODE, fromIntent, pendingIntentFlags);
    }
    firstRunIntent.putExtra(FirstRunActivity.EXTRA_CHROME_LAUNCH_INTENT, pendingIntent);
}
 
Example 9
Source File: TrackerService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mHasGPSFix = false;

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    IGISApplication application = (IGISApplication) getApplication();
    String authority = application.getAuthority();
    String tracks = TrackLayer.TABLE_TRACKS;
    mContentUriTracks = Uri.parse("content://" + authority + "/" + tracks);
    String points = TrackLayer.TABLE_TRACKPOINTS;
    mContentUriTrackPoints = Uri.parse("content://" + authority + "/" + points);

    mPoint = new GeoPoint();
    mValues = new ContentValues();

    String name = getPackageName() + "_preferences";
    mSharedPreferences = getSharedPreferences(name, MODE_MULTI_PROCESS);
    mSharedPreferencesTemp = getSharedPreferences(TEMP_PREFERENCES, MODE_PRIVATE);

    mTicker = getString(R.string.tracks_running);
    mSmallIcon = R.drawable.ic_action_maps_directions_walk;
    mLargeIcon = NotificationHelper.getLargeIcon(mSmallIcon, getResources());

    Intent intentSplit = new Intent(this, TrackerService.class);
    intentSplit.setAction(ACTION_SPLIT);
    int flag = PendingIntent.FLAG_UPDATE_CURRENT;
    mSplitService = PendingIntent.getService(this, 0, intentSplit, flag);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
 
Example 10
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    int icon = R.drawable.ic_notification_download;
    Bitmap largeIcon = NotificationHelper.getLargeIcon(icon, getResources());

    mProgressIntent = new Intent(ACTION_UPDATE);
    Intent intent = new Intent(this, LayerFillService.class);
    intent.setAction(ACTION_STOP);
    int flag = PendingIntent.FLAG_UPDATE_CURRENT;
    PendingIntent stop = PendingIntent.getService(this, 0, intent, flag);
    intent.setAction(ACTION_SHOW);
    PendingIntent show = PendingIntent.getService(this, 0, intent, flag);

    mBuilder = createBuilder(this, R.string.start_fill_layer);
    mBuilder.setSmallIcon(icon).setLargeIcon(largeIcon)
            .setAutoCancel(false)
            .setOngoing(true)
            .setContentIntent(show)
            .addAction(R.drawable.ic_action_cancel_dark, getString(R.string.tracks_stop), stop);
    mIsCanceled = false;

    mQueue = new LinkedList<>();
    mIsRunning = false;
    mHandler = new Handler(Looper.getMainLooper()){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle resultData = msg.getData();
            Toast.makeText(LayerFillService.this, resultData.getString(BUNDLE_MSG_KEY), Toast.LENGTH_LONG).show();
        }
    };

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String title = getString(R.string.start_fill_layer);
        mBuilder.setWhen(System.currentTimeMillis()).setContentTitle(title).setTicker(title);
        startForeground(FILL_NOTIFICATION_ID, mBuilder.build());
    }
}
 
Example 11
Source File: TileDownloadService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    //android.os.Debug.waitForDebugger();

    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "TileDownloadService.onCreate() is starting");
    }

    mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent intentStop = getStopIntent();
    intentStop.setAction(ACTION_STOP);
    int flag = PendingIntent.FLAG_UPDATE_CURRENT;
    PendingIntent stop = PendingIntent.getService(this, 0, intentStop, flag);

    int icon = R.drawable.ic_notification_download;
    Bitmap largeIcon = NotificationHelper.getLargeIcon(icon, getResources());

    mBuilder = createBuilder(this, R.string.download_tiles);
    mBuilder.setSmallIcon(icon)
            .setLargeIcon(largeIcon)
            .setAutoCancel(false)
            .setOngoing(true)
            .addAction(R.drawable.ic_action_cancel_dark, getString(R.string.cancel), stop);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String title = getString(R.string.download_tiles);
        mBuilder.setContentTitle(title).setTicker(title).setWhen(System.currentTimeMillis());
        startForeground(TILE_DOWNLOAD_NOTIFICATION_ID, mBuilder.build());
    }

    mQueue = new ConcurrentLinkedQueue<>();
}
 
Example 12
Source File: RebuildCacheService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mProgressIntent = new Intent(ACTION_UPDATE);
    Intent intent = new Intent(this, RebuildCacheService.class);
    intent.setAction(ACTION_STOP);
    int flag = PendingIntent.FLAG_UPDATE_CURRENT;
    PendingIntent stop = PendingIntent.getService(this, 0, intent, flag);
    intent.setAction(ACTION_SHOW);
    PendingIntent show = PendingIntent.getService(this, 0, intent, flag);
    mBuilder = createBuilder(this, R.string.rebuild_cache);

    int icon = R.drawable.ic_notification_rebuild_cache;
    Bitmap largeIcon = NotificationHelper.getLargeIcon(icon, getResources());
    mBuilder.setSmallIcon(icon).setLargeIcon(largeIcon);
    icon = R.drawable.ic_action_cancel_dark;

    mBuilder.setAutoCancel(false)
            .setOngoing(true)
            .setContentIntent(show)
            .addAction(icon, getString(android.R.string.cancel), stop);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String title = getString(R.string.rebuild_cache);
        mBuilder.setWhen(System.currentTimeMillis()).setContentTitle(title).setTicker(title);
        startForeground(NOTIFICATION_ID, mBuilder.build());
    }

    mQueue = new LinkedList<>();
}
 
Example 13
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void listing15_29_30_31_32() {
  if (ActivityCompat.checkSelfPermission(this,
    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    return;
  }

  int flags = PendingIntent.FLAG_UPDATE_CURRENT;
  Intent intent = new Intent(this, WalkFenceReceiver.class);
  PendingIntent awarenessIntent = PendingIntent.getBroadcast(this, -1,
    intent, flags);

  // Listing 15-29: Creating Awareness Fences
  // Near one of my custom beacons.
  BeaconState.TypeFilter typeFilter
    = BeaconState.TypeFilter.with("com.professionalandroid.apps.beacon", "my_type");

  AwarenessFence beaconFence = BeaconFence.near(typeFilter);

  // While walking.
  AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);

  // Having just plugged in my headphones.
  AwarenessFence headphoneFence = HeadphoneFence.pluggingIn();

  // Within 1km of Google for longer than a minute.
  double lat = 37.4220233;
  double lng = -122.084252;
  double radius = 1000; // meters
  long dwell = 60000; // milliseconds.
  AwarenessFence locationFence = LocationFence.in(lat, lng, radius, dwell);

  // In the morning
  AwarenessFence timeFence = TimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_MORNING);

  // During holidays
  AwarenessFence holidayFence = TimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_HOLIDAY);

  // Listing 15-30: Combining Awareness Fences
  // Trigger when headphones are plugged in and walking in the morning
  // either within a kilometer of Google or near one of my beacons --
  // but not on a holiday.
  AwarenessFence morningWalk = AwarenessFence
                                 .and(activityFence,
                                   headphoneFence,
                                   timeFence,
                                   AwarenessFence.or(locationFence,
                                     beaconFence),
                                   AwarenessFence.not(holidayFence));

  // Listing 15-31: Creating an Awareness Fence Update Request
  FenceUpdateRequest fenceUpdateRequest
    = new FenceUpdateRequest.Builder()
        .addFence(WalkFenceReceiver.WALK_FENCE_KEY, morningWalk, awarenessIntent)
        .build();

  // Listing 15-32: Adding a new Awareness Fence
  Awareness.FenceApi.updateFences(
    mGoogleApiClient, fenceUpdateRequest).setResultCallback(new ResultCallback<Status>() {
    @Override
    public void onResult(@NonNull Status status) {
      if (!status.isSuccess()) {
        Log.d(TAG, "Fence could not be registered: " + status);
      }
    }
  });
}
 
Example 14
Source File: TrackerService.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void addNotification() {
    String name = "";
    String selection = TrackLayer.FIELD_ID + " = ?";
    String[] proj = new String[]{TrackLayer.FIELD_NAME};
    String[] args = new String[]{mTrackId};
    try {
        Cursor currentTrack = getContentResolver().query(mContentUriTracks, proj, selection, args, null);
        if (null != currentTrack) {
            if (currentTrack.moveToFirst())
                name = currentTrack.getString(0);
            currentTrack.close();
        }
    } catch (SQLiteException ignored){
    }

    String title = String.format(getString(R.string.tracks_title), name);
    Intent intentStop = new Intent(this, TrackerService.class);
    intentStop.setAction(ACTION_STOP);
    int flag = PendingIntent.FLAG_UPDATE_CURRENT;
    PendingIntent stopService = PendingIntent.getService(this, 0, intentStop, flag);

    NotificationCompat.Builder builder = createBuilder(this, R.string.title_edit_by_walk);
    builder.setContentIntent(mOpenActivity)
            .setSmallIcon(mSmallIcon)
            .setLargeIcon(mLargeIcon)
            .setTicker(mTicker)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(false)
            .setContentTitle(title)
            .setContentText(mTicker)
            .setOngoing(true);

    int resource = R.drawable.ic_location;
    builder.addAction(resource, getString(R.string.tracks_open), mOpenActivity);
    resource = R.drawable.ic_action_cancel_dark;
    builder.addAction(resource, getString(R.string.tracks_stop), stopService);

    mNotificationManager.notify(TRACK_NOTIFICATION_ID, builder.build());
    startForeground(TRACK_NOTIFICATION_ID, builder.build());
    Toast.makeText(this, title, Toast.LENGTH_SHORT).show();
}