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:edu.cmu.mpcs.dashboard.TagViewer.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.tag_viewer);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Intent intent = this.getIntent();
    writeContent = intent.getStringExtra("writeContent");

    mLoginButton = new LoginButton(getApplicationContext());

    // if(flag == true)

    Log.d("TAG_VIEWER", "writeConent:" + writeContent);
    // setContentView(R.layout.tag_viewer);
    mNfcPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    // mTagContent = (LinearLayout) findViewById(R.id.list);
    // mTitle = (TextView) findViewById(R.id.title);

    Log.d("TAG_VIEWER", "Utility.mFacebook is " + Utility.mFacebook);
    if (Utility.mFacebook == null) {
        InitializeLogin = true;/*from  www  .j av a  2  s . co m*/

    }
    // Create the Facebook Object using the app id.
    edu.cmu.mpcs.dashboard.Utility.mFacebook = new Facebook(APP_ID);
    // Instantiate the asynrunner object for asynchronous api calls.
    edu.cmu.mpcs.dashboard.Utility.mAsyncRunner = new AsyncFacebookRunner(
            edu.cmu.mpcs.dashboard.Utility.mFacebook);

    Log.d("TAG_VIEWER", "in oncreate in TagViewer is session valid?:" + Utility.mFacebook.isSessionValid());

    mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see FbAPIs.java");
        return;
    }

    SessionStore.restore(Utility.mFacebook, this);
    SessionEvents.addAuthListener(new FbAPIsAuthListener());
    SessionEvents.addLogoutListener(new FbAPIsLogoutListener());
    // SessionEvents.r

    if (Utility.mFacebook.isSessionValid()) {
        requestUserData();

    }

    // TODO do something about - dont call resolve intent by
    // default.
    if (writeContent == null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Log.d("TAG_VIEWER", "in OnCreate Before reading");
        loginIntent = intent;

        if (InitializeLogin) { /*
                               * This is if we come to tag viewer without
                               * having started dashboard activity
                               */
            mLoginButton.initializeFbLogin();
        } else { /* This is we if read the tag while in dashboard! */
            resolveIntent(intent);

        }
        // mLoginButton.performLogout();

    } else {
        Log.d("TAG_VIEWER", "Before creating alert dialog");
        builder = new AlertDialog.Builder(TagViewer.this);
        dialog = builder.create();
        builder.setTitle("Touch tag to write").setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                Log.d("TAG_VIEWER", "On cancel called");
                disableTagWriteMode();

            }
        }).create();
        dialog.setTitle("touch tag to write");
        dialog.show();
        dialog.setOnDismissListener(new OnDismissListener() {

            public void onDismiss(DialogInterface dialog) {
                // TODO Auto-generated method stub
                Log.d("TAG_VIEWER", "On dismiss called");
                disableTagWriteMode();

            }
        });
        // builder.setCancelable(true);
        // builder.setOnCancelListener(new
        // DialogInterface.OnCancelListener() {
        // public void onCancel(DialogInterface dialog) {
        // Log.d("TAG_VIEWER","On cancel called");
        // disableTagWriteMode();
        //
        // }
        // }).create().show();
    }

    // Tag writing mode
    if (writeContent != null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Log.d("TAG_VIEWER", "in Oncreate Before writing");

        Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        try {
            WriteToTag.write(detectedTag, writeContent);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.d("TAG_VIEWER", "in on create, writing to tag");
    }
    Log.d("TAG_VIEWER", "in create");

}

From source file:com.getmarco.weatherstationviewer.gcm.StationGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  w  w  .jav a  2s .  co m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, StationListActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Station update").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:cn.mdict.services.DownloadService.java

public void downloadFile(final String url, final String title, final String targetFile,
        Class<?> activityClass) {
    if (downloading.containsKey(url))
        return;//from  ww w .j a va  2  s  .c  o  m
    final PendingIntent contentIntent = PendingIntent.getActivity(context, url.hashCode(),
            new Intent(context, activityClass), 0);
    final DownloadTask downloadTask = new DownloadTask();
    downloading.put(url, downloadTask);
    executorService.execute(new Runnable() {
        @Override
        public void run() {
            downloadTask.download(context, contentIntent, title, url, targetFile);
            //TODO Need more works to notify caller that the job is done.
            //MiscUtils.installApk(context, targetFile);
        }
    });
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private void generateNotification(Context context, String msg, String title, Intent intent) {
    int icon = R.drawable.status_icon;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, title, when);
    notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0));
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    SharedPreferences settings = Prefs.get(context);
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32);
    editor.commit();/* w  w w .  ja va 2 s . c  o  m*/
}

From source file:de.wikilab.android.friendica01.FileUploadService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.i("Andfrnd/UploadFile", "onHandleIntent exec");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    //Instantiate the Notification:
    CharSequence tickerText = "Uploading...";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    notification.setLatestEventInfo(context, "Upload in progress...", "You are notified here when it completes",
            nullIntent);/*  w w w.  j  av a2  s. c o m*/

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_PROGRESS_ID, notification);
    /*
    final TwLogin login = new TwLogin();
    login.initialize(FileUploadService.this);
    login.doLogin(FileUploadService.this, null, false);
            
    if (!login.isLoginOK()) {
       showFailMsg(FileUploadService.this, "Invalid login data or no network connection");
       return;
    }
    */
    Bundle intentPara = intent.getExtras();
    fileToUpload = (Uri) intentPara.getParcelable(Intent.EXTRA_STREAM);
    descText = intentPara.getString(EXTRA_DESCTEXT);
    subject = intentPara.getString(Intent.EXTRA_SUBJECT);

    if (targetFilename == null || targetFilename.equals(""))
        targetFilename = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt";

    String fileSpec = Max.getRealPathFromURI(FileUploadService.this, fileToUpload);

    String tempFile = Max.IMG_CACHE_DIR + "/imgUploadTemp_" + System.currentTimeMillis() + ".jpg";
    Max.resizeImage(fileSpec, tempFile, 1024, 768);

    try {
        Log.i("Andfrnd/UploadFile", "before uploadFile");
        final TwAjax uploader = new TwAjax(FileUploadService.this, true, true);
        uploader.addPostFile(new TwAjax.PostFile("media", targetFilename, tempFile));
        uploader.addPostData("status", descText);
        uploader.addPostData("title", subject);
        uploader.addPostData("source",
                "<a href='http://friendica-for-android.wiki-lab.net'>Friendica for Android</a>");
        uploader.uploadFile(Max.getServer(this) + "/api/statuses/update", null);
        Log.i("Andfrnd/UploadFile", "after uploadFile");
        Log.i("Andfrnd/UploadFile", "isSuccess() = " + uploader.isSuccess());
        Log.i("Andfrnd/UploadFile", "getError() = " + uploader.getError());

        mNotificationManager.cancel(UPLOAD_PROGRESS_ID);
        if (uploader.isSuccess() && uploader.getError() == null) {
            JSONObject result = null;
            try {
                Log.i("Andfrnd/UploadFile", "JSON RESULT: " + uploader.getHttpCode());
                result = (JSONObject) uploader.getJsonResult();

                String postedText = result.getString("text");
                showSuccessMsg(FileUploadService.this);

            } catch (Exception e) {
                String errMes = e.getMessage() + " | " + uploader.getResult();
                if (result != null)
                    try {
                        errMes = result.getString("error");
                    } catch (JSONException fuuuuJava) {
                    }

                showFailMsg(FileUploadService.this, errMes);

                e.printStackTrace();
            }
        } else if (uploader.getError() != null) {
            showFailMsg(FileUploadService.this, uploader.getError().toString());
        } else {
            showFailMsg(FileUploadService.this, uploader.getResult());
        }

    } finally {
        new File(tempFile).delete();
    }
}

From source file:com.rampgreen.caretakermobile.GcmIntentService.java

private void sendNotification(String notificationTitle, String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Bundle bundle = new Bundle();
    bundle.putString(Constants.NOTIFICATION_MSG, msg);
    bundle.putString(Constants.CALLED_COMPONENT, Constants.SERVICE_GCM_INTENT);

    Intent notificationIntent = new Intent(this, ActivityNotification.class);
    notificationIntent.putExtras(bundle);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

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

    mBuilder.setContentIntent(contentIntent);
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:com.etime.ETimeActivity.java

/**
 * Notify the user with the message "message". Notification is set to
 * on-going, on-going is needed to tell android not to kill the app.
 * The phone with vibrate, and light up on notification. If the message
 * is the exact same message as the last message notified then the
 * notification is not set again.//  ww  w.j a  v a  2s.c  o m
 * @param message  Message to notify user with
 */
protected void notify(String message) {
    if (message.equalsIgnoreCase(lastNotificationMessage)) {
        return;
    } else {
        lastNotificationMessage = message;
    }

    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    Context context = getApplicationContext();
    CharSequence contentTitle = "ETime";
    Intent notificationIntent = new Intent(this, ETimeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.setLatestEventInfo(context, contentTitle, message, contentIntent);

    mManager.notify("ETime", APP_ID, notification);
}

From source file:com.skubit.android.billing.BillingServiceBinder.java

@Override
public Bundle getBuyIntent(int apiVersion, String userId, String packageName, String sku, String type,
        String developerPayload) throws RemoteException {

    Bundle bundle = new Bundle();
    if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(sku) || TextUtils.isEmpty(type)) {
        Log.d(TAG, "Missing required parameter");
        bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_DEVELOPER_ERROR);
        return bundle;
    }// www.j  a v a  2s. c  o  m

    if (apiVersion != 1) {
        Log.d(TAG, "Unsupported API: " + apiVersion);
        bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_BILLING_UNAVAILABLE);
        return bundle;
    }

    if (!isValidType(type)) {
        Log.d(TAG, "Incorrect billing type: " + type);
        bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_BILLING_UNAVAILABLE);
        return bundle;
    }

    int packValidate = validatePackageIsOwnedByCaller(packageName);
    if (packValidate != BillingResponseCodes.RESULT_OK) {
        Log.d(TAG, "Package is not owned by caller");
        bundle.putInt("RESPONSE_CODE", packValidate);
        return bundle;
    }

    if (!hasAccess(userId, packageName)) {
        Log.d(TAG, "User account not configured");
        bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_USER_ACCESS);
        return bundle;
    }
    /**
     * DO we already own this product? method: userId, packageName,
     * productId bundle.putInt("RESPONSE_CODE",
     * BillingResponseCodes.RESULT_ITEM_ALREADY_OWNED)
     */
    Intent purchaseIntent = null;
    if ("inapp".equals(type)) {
        purchaseIntent = makePurchaseIntent(apiVersion, userId, packageName, sku, developerPayload, type);
    }

    if (purchaseIntent == null) {
        bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_DEVELOPER_ERROR);
        return bundle;
    }
    Utils.changeAccount(mContext, userId);

    PendingIntent pending = PendingIntent.getActivity(mContext, (sku + userId).hashCode(), purchaseIntent, 0);
    bundle.putParcelable("BUY_INTENT", pending);

    bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_OK);
    return bundle;
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);/*from w ww  . ja  v  a  2s.co  m*/

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}