Example usage for android.app PendingIntent getActivity

List of usage examples for android.app PendingIntent getActivity

Introduction

In this page you can find the example usage for android.app PendingIntent getActivity.

Prototype

public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a new activity, like calling Context#startActivity(Intent) Context.startActivity(Intent) .

Usage

From source file:com.behance.sdk.services.BehanceSDKPublishProjectService.java

private PendingIntent createPendingIntent(Intent paramIntent) {
      return PendingIntent.getActivity(this, 0, paramIntent, 134217728);
  }

From source file:edu.polyu.screamalert.SoundProcessing.java

@SuppressWarnings("unchecked")
public static void initialize(Context context) {
    thisContext = context;//from www .  j  a v  a2s.c  om
    x = new float[samplePerFrm];
    subx = new float[frameShift]; // Samples in a sub-frame
    mfcc = new MFCC(samplePerFrm, Config.RECORDER_SAMPLERATE, numMfcc);
    ccBuf = new CircularFifoBuffer(K); // Buffer storing K mfcc vectors
    dccBuf = new CircularFifoBuffer(K); // Buffer storing K delta-mfcc vectors
    pDet = new YinPitchDetector(Config.RECORDER_SAMPLERATE, samplePerFrm);
    piBuf = new CircularFifoBuffer(K);
    pkBuf = new CircularFifoBuffer(K);
    mu_z = new double[] { VoiceQuality.JITTER_MEAN, VoiceQuality.SHIMMER_MEAN }; // Jitter and shimmer mean
    sigma_z = new double[] { VoiceQuality.JITTER_STD, VoiceQuality.SHIMMER_STD }; // Jitter and shimmer stddev
    aList = new ArrayList<double[]>();
    enBuf = new CircularFifoBuffer(enBufSize); // Circular buffer storing energy profile of the latest K frames
    frmBuf = new CircularFifoBuffer(K); // Buffer storing K latest frames of audio signals */

    for (int k = 0; k < K; k++) {
        ccBuf.add(new double[numMfcc + 1]); // Initialize MFCC FIFO buffers
        dccBuf.add(new double[numMfcc + 1]); // Initialize delta MFCC FIFO buffers
        piBuf.add(-1.0D); // Initialize pitch FIFO buffer for computing jitter and shimmer
        pkBuf.add(0.0D); // Initialize peak amplitude FIFO buffer for computing shimmer
        frmBuf.add(new double[samplePerFrm]); // Initialize frame buffer
    }
    for (int k = 0; k < enBufSize; k++) {
        enBuf.add(new double[1]); // Initialize energy buffer
    }
    mainIntent = new Intent(thisContext, SoundProcessingSetting.class);
    mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pIntent = PendingIntent.getActivity(thisContext, 0, mainIntent, 0); // Go back to MainActivity when user press the notification
    noti = new NotificationCompat.Builder(thisContext)
            .setContentTitle(
                    thisContext.getString(R.string.app_name) + " " + thisContext.getString(R.string.running))
            .setContentText(thisContext.getString(R.string.configure)).setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent).build();
    noti.flags = Notification.FLAG_FOREGROUND_SERVICE;
    if (SoundProcessingActivity.thisActivity == null)
        calibrateDialog = new ProgressDialog(Exchanger.thisContext);
    else
        calibrateDialog = new ProgressDialog(SoundProcessingActivity.thisActivity);
}

From source file:com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);/*from  w  w  w. j ava2 s.c  om*/

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}

From source file:com.snappy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 */// w  w  w.  j  a  v  a 2s  .  co  m
private void generateNotification(Context context, String message, String fromName, Bundle pushExtras,
        String body) {

    db = new LocalDB(context);
    List<LocalMessage> myMessages = db.getAllMessages();

    // Open a new activity called GCMMessageView
    Intent intento = new Intent(this, SplashScreenActivity.class);
    intento.replaceExtras(pushExtras);
    // Pass data to the new activity
    intento.putExtra(Const.PUSH_INTENT, true);
    intento.setAction(Long.toString(System.currentTimeMillis()));
    intento.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

    // Starts the activity on notification click
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the notification with a notification builder
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis())
            .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setContentText(body).setContentIntent(pIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message));

    for (int i = 0; i < myMessages.size(); i++) {

        inboxStyle.addLine(myMessages.get(i).getMessage());
    }

    notification.setStyle(inboxStyle);

    // Remove the notification on click
    //notification.flags |= Notification.FLAG_AUTO_CANCEL;
    //notification.defaults |= Notification.DEFAULT_VIBRATE;
    //notification.defaults |= Notification.DEFAULT_SOUND;
    //notification.defaults |= Notification.DEFAULT_LIGHTS;

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(R.string.app_name, notification.build());
    {
        // Wake Android Device when notification received
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        final PowerManager.WakeLock mWakelock = pm
                .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
        mWakelock.acquire();
        // Timer before putting Android Device to sleep mode.
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            public void run() {
                mWakelock.release();
            }
        };
        timer.schedule(task, 5000);
    }
}

From source file:de.yaacc.upnp.server.YaaccUpnpServerService.java

/**
 * Displays the notification./*  ww w .  java2s  . c  o  m*/
 */
private void showNotification() {
    Intent notificationIntent = new Intent(this, YaaccUpnpServerControlActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setOngoing(true)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Yaacc Upnp Server")
            .setContentText(preferences
                    .getString(getApplicationContext().getString(R.string.settings_local_server_name_key), ""));
    mBuilder.setContentIntent(contentIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NotificationId.UPNP_SERVER.getId(), mBuilder.build());
}

From source file:com.pti.mates.GcmIntentService.java

private void sendNotificationChat(String msg, String senderid) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    /*Cursor caux;// ww w. ja  va 2  s.com
    caux = getApplicationContext().getContentResolver().query(DataProvider.CONTENT_URI_PROFILE, new String[] {DataProvider.COL_ID}, DataProvider.COL_FBID + "=" + senderid, null, null);
    Intent intent = new Intent(this, ChatActivity.class);
    intent.putExtra(Common.PROFILE_ID, caux.getString(caux.getColumnIndex(DataProvider.COL_ID)));*/
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(getApplicationContext(), MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("New chat message")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:edu.stanford.junction.sample.partyware.ImgurUploadService.java

/**
 * This method uploads an image from the given uri. It does the uploading in
 * small chunks to make sure it doesn't over run the memory.
 * //from   w w w .  jav a2s . c  o m
 * @param uri
 *            image location
 * @return map containing data from interaction
 */
private String readPictureDataAndUpload(final Uri uri) {
    Log.i(this.getClass().getName(), "in readPictureDataAndUpload(Uri)");
    try {
        final AssetFileDescriptor assetFileDescriptor = getContentResolver().openAssetFileDescriptor(uri, "r");
        final int totalFileLength = (int) assetFileDescriptor.getLength();
        assetFileDescriptor.close();

        // Create custom progress notification
        mProgressNotification = new Notification(R.drawable.icon, getString(R.string.imgur_upload_in_progress),
                System.currentTimeMillis());
        // set as ongoing
        mProgressNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        // set custom view to notification
        mProgressNotification.contentView = generateProgressNotificationView(0, totalFileLength);
        //empty intent for the notification
        final Intent progressIntent = new Intent();
        final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, progressIntent, 0);
        mProgressNotification.contentIntent = contentIntent;
        // add notification to manager
        mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification);

        final InputStream inputStream = getContentResolver().openInputStream(uri);

        final String boundaryString = "Z." + Long.toHexString(System.currentTimeMillis())
                + Long.toHexString((new Random()).nextLong());
        final String boundary = "--" + boundaryString;
        final HttpURLConnection conn = (HttpURLConnection) (new URL("http://imgur.com/api/upload.json"))
                .openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-type", "multipart/form-data; boundary=\"" + boundaryString + "\"");
        conn.setUseCaches(false);
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setChunkedStreamingMode(CHUNK_SIZE);
        final OutputStream hrout = conn.getOutputStream();
        final PrintStream hout = new PrintStream(hrout);
        hout.println(boundary);
        hout.println("Content-Disposition: form-data; name=\"key\"");
        hout.println("Content-Type: text/plain");
        hout.println();

        Random rng = new Random();
        String key = API_KEYS[rng.nextInt(API_KEYS.length)];
        hout.println(key);

        hout.println(boundary);
        hout.println("Content-Disposition: form-data; name=\"image\"");
        hout.println("Content-Transfer-Encoding: base64");
        hout.println();
        hout.flush();
        {
            final Base64OutputStream bhout = new Base64OutputStream(hrout);
            final byte[] pictureData = new byte[READ_BUFFER_SIZE_BYTES];
            int read = 0;
            int totalRead = 0;
            long lastLogTime = 0;
            while (read >= 0) {
                read = inputStream.read(pictureData);
                if (read > 0) {
                    bhout.write(pictureData, 0, read);
                    totalRead += read;
                    if (lastLogTime < (System.currentTimeMillis() - PROGRESS_UPDATE_INTERVAL_MS)) {
                        lastLogTime = System.currentTimeMillis();
                        Log.d(this.getClass().getName(), "Uploaded " + totalRead + " of " + totalFileLength
                                + " bytes (" + (100 * totalRead) / totalFileLength + "%)");

                        //make a final version of the total read to make the handler happy
                        final int totalReadFinal = totalRead;
                        mHandler.post(new Runnable() {
                            public void run() {
                                mProgressNotification.contentView = generateProgressNotificationView(
                                        totalReadFinal, totalFileLength);
                                mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification);
                            }
                        });
                    }
                    bhout.flush();
                    hrout.flush();
                }
            }
            Log.d(this.getClass().getName(), "Finishing upload...");
            // This close is absolutely necessary, this tells the
            // Base64OutputStream to finish writing the last of the data
            // (and including the padding). Without this line, it will miss
            // the last 4 chars in the output, missing up to 3 bytes in the
            // final output.
            bhout.close();
            Log.d(this.getClass().getName(), "Upload complete...");
            mProgressNotification.contentView.setProgressBar(R.id.UploadProgress, totalFileLength, totalRead,
                    false);
            mNotificationManager.cancelAll();
        }

        hout.println(boundary);
        hout.flush();
        hrout.close();

        inputStream.close();

        Log.d(this.getClass().getName(), "streams closed, " + "now waiting for response from server");

        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        final StringBuilder rData = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            rData.append(line).append('\n');
        }

        return rData.toString();
    } catch (final IOException e) {
        Log.e(this.getClass().getName(), "Upload failed", e);
    }

    return null;
}

From source file:com.granita.icloudcalsync.syncadapter.DavSyncAdapter.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override/*from ww  w  .  ja v a 2  s  .co  m*/
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.i(TAG, "Performing sync for authority " + authority);

    // set class loader for iCal4j ResourceLoader
    Thread.currentThread().setContextClassLoader(getContext().getClassLoader());

    // create httpClient, if necessary
    httpClientLock.writeLock().lock();
    if (httpClient == null) {
        Log.d(TAG, "Creating new DavHttpClient");
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
        httpClient = DavHttpClient.create();
    }

    // prevent httpClient shutdown until we're ready by holding a read lock
    // acquiring read lock before releasing write lock will downgrade the write lock to a read lock
    httpClientLock.readLock().lock();
    httpClientLock.writeLock().unlock();

    // TODO use VCard 4.0 if possible
    AccountSettings accountSettings = new AccountSettings(getContext(), account);
    Log.d(TAG, "Server supports VCard version " + accountSettings.getAddressBookVCardVersion());

    Exception exceptionToShow = null; // exception to show notification for
    Intent exceptionIntent = null; // what shall happen when clicking on the exception notification
    try {
        // get local <-> remote collection pairs
        Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider);
        if (syncCollections == null)
            Log.i(TAG, "Nothing to synchronize");
        else
            try {
                for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet())
                    new SyncManager(entry.getKey(), entry.getValue())
                            .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult);

            } catch (DavException ex) {
                syncResult.stats.numParseExceptions++;
                Log.e(TAG, "Invalid DAV response", ex);
                exceptionToShow = ex;

            } catch (HttpException ex) {
                if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) {
                    Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex);
                    syncResult.stats.numAuthExceptions++; // hard error

                    exceptionToShow = ex;
                    exceptionIntent = new Intent(context, AccountActivity.class);
                    exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account);
                } else if (ex.isClientError()) {
                    Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex);
                    syncResult.stats.numParseExceptions++; // hard error
                    exceptionToShow = ex;
                } else {
                    Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex);
                    syncResult.stats.numIoExceptions++; // soft error
                }
            } catch (LocalStorageException ex) {
                syncResult.databaseError = true; // hard error
                Log.e(TAG, "Local storage (content provider) exception", ex);
                exceptionToShow = ex;
            } catch (IOException ex) {
                syncResult.stats.numIoExceptions++; // soft error
                Log.e(TAG, "I/O error (Android will try again later)", ex);
                if (ex instanceof SSLException) // always notify on SSL/TLS errors
                    exceptionToShow = ex;
            } catch (URISyntaxException ex) {
                syncResult.stats.numParseExceptions++; // hard error
                Log.e(TAG, "Invalid URI (file name) syntax", ex);
                exceptionToShow = ex;
            }
    } finally {
        // allow httpClient shutdown
        httpClientLock.readLock().unlock();
    }

    // show sync errors as notification
    if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (exceptionIntent == null)
            exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS));

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0);
        Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher)
                .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true)
                .setWhen(System.currentTimeMillis())
                .setContentTitle(context.getString(R.string.sync_error_title))
                .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name)
                .setStyle(new Notification.BigTextStyle()
                        .bigText(account.name + ":\n" + ExceptionUtils.getFullStackTrace(exceptionToShow)))
                .setContentIntent(contentIntent);

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(account.name.hashCode(), builder.build());
    }

    Log.i(TAG, "Sync complete for " + authority);
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get lobster_two asset and create typeface
    // Set action bar title to lobster_two typeface
    lobsterTwo = Typeface.createFromAsset(getAssets(), "lobster_two.otf");

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);

    if (actionBarTitleView != null) {
        actionBarTitleView.setTypeface(lobsterTwo);
        actionBarTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f);
        actionBarTitleView.setTextColor(getResources().getColor(R.color.blue));
    }//from w  w w . jav a 2s. c  o m

    setContentView(R.layout.activity_main);

    // Hide keyboard on app launch
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Get NFC service and adapter
    NfcManager nfcManager = (NfcManager) this.getSystemService(Context.NFC_SERVICE);
    nfcAdapter = nfcManager.getDefaultAdapter();

    // Create PendingIntent for enableForegroundDispatch for NFC tag discovery
    pIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    readFromJSON();
    writeToJSON();
    readFromJSON();

    // If Android 4.2 or bigger
    if (Build.VERSION.SDK_INT > 16) {
        // Check if TapUnlock folder exists, if not, create directory
        File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock");
        boolean folderSuccess = true;

        if (!folder.exists()) {
            folderSuccess = folder.mkdir();
        }

        try {
            // If blur var bigger than 0
            if (settings.getInt("blur") > 0) {
                // If folder exists or successfully created
                if (folderSuccess) {
                    // If blurred wallpaper file doesn't exist
                    if (!ImageUtils.doesBlurredWallpaperExist()) {
                        // Get default wallpaper
                        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                        final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable();

                        if (wallpaperDrawable != null) {
                            // Default wallpaper to bitmap - fastBlur the bitmap - store bitmap
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable);

                                    Bitmap blurredWallpaper = null;
                                    if (bitmapToBlur != null)
                                        blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur,
                                                blur);

                                    if (blurredWallpaper != null) {
                                        ImageUtils.storeImage(blurredWallpaper);
                                    }
                                }
                            }).start();
                        }
                    }
                }
            }

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

    // Initialize layout items
    pinEdit = (EditText) findViewById(R.id.pinEdit);
    pinEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
    Button setPin = (Button) findViewById(R.id.setPin);
    ImageButton newTag = (ImageButton) findViewById(R.id.newTag);
    enabled_disabled = (TextView) findViewById(R.id.enabled_disabled);
    Switch toggle = (Switch) findViewById(R.id.toggle);
    seekBar = (SeekBar) findViewById(R.id.seekBar);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Button refreshWallpaper = (Button) findViewById(R.id.refreshWallpaper);
    listView = (ListView) findViewById(R.id.listView);
    backgroundBlurValue = (TextView) findViewById(R.id.backgroundBlurValue);
    noTags = (TextView) findViewById(R.id.noTags);

    // Initialize TagAdapter
    adapter = new TagAdapter(this, tags);

    registerForContextMenu(listView);

    // Set listView adapter to TapAdapter object
    listView.setAdapter(adapter);

    // Set click, check and seekBar listeners
    setPin.setOnClickListener(this);
    newTag.setOnClickListener(this);
    refreshWallpaper.setOnClickListener(this);
    toggle.setOnCheckedChangeListener(this);
    seekBar.setOnSeekBarChangeListener(this);

    // Set seekBar progress to blur var
    try {
        seekBar.setProgress(settings.getInt("blur"));

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

    // Refresh the listView height
    updateListViewHeight(listView);

    // If no tags, show 'Press + to add Tags' textView
    if (tags.length() == 0)
        noTags.setVisibility(View.VISIBLE);

    else
        noTags.setVisibility(View.INVISIBLE);

    // Scroll up
    scrollView = (ScrollView) findViewById(R.id.scrollView);

    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, scrollView.getTop());
            scrollView.fullScroll(View.FOCUS_UP);
        }
    });

    // If lockscreen enabled, initialize switch, text and start service
    try {
        if (settings.getBoolean("lockscreen")) {
            onStart = true;
            enabled_disabled.setText(R.string.lockscreen_enabled);
            enabled_disabled.setTextColor(getResources().getColor(R.color.green));

            toggle.setChecked(true);
        }

    } catch (JSONException e1) {
        e1.printStackTrace();
    }
}

From source file:org.droidkit.app.UpdateService.java

private void notifyDownloading(String json) {
    Intent intent = new Intent(this, UpdateActivity.class);
    intent.putExtra("downloading", true);
    intent.putExtra("json", json);

    String desc = "Downloading " + getString(getApplicationInfo().labelRes);
    PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
    Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...",
            System.currentTimeMillis());
    n.flags = Notification.FLAG_ONGOING_EVENT;
    n.contentIntent = pending;/*from  w  w  w  .ja  v  a2s  . c o m*/

    RemoteViews view = new RemoteViews(getPackageName(),
            Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT));
    view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc);
    view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true);
    view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID),
            android.R.drawable.stat_sys_download);

    n.contentView = view;

    mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n);
}