List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.anjlab.android.iab.v3.BillingProcessor.java
private void bindPlayServices() { try {/*from ww w .j a v a 2 s. c o m*/ Intent iapIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); iapIntent.setPackage("com.android.vending"); getContext().bindService(iapIntent, serviceConnection, Context.BIND_AUTO_CREATE); } catch (Exception e) { Log.e(LOG_TAG, e.toString()); } }
From source file:com.google.fpl.gim.examplegame.MainActivity.java
@Override public void onDestroy() { Utils.logDebug(TAG, "onDestroy"); super.onDestroy(); if (isFinishing()) { // Stop the service from running in the background if the app exits. Intent intent = new Intent(this, MainService.class); intent.setPackage(getPackageName()); stopService(intent);//w w w . ja v a 2 s .c o m } }
From source file:com.samuelcastro.cordova.InstagramSharePlugin.java
private void shareImage(String imageString, String captionString) { if (imageString != null && imageString.length() > 0) { byte[] imageData = Base64.decode(imageString, 0); File file = null;//from w w w . j a va 2 s. c o m FileOutputStream os = null; File parentDir = this.webView.getContext().getExternalFilesDir(null); File[] oldImages = parentDir.listFiles(OLD_IMAGE_FILTER); for (File oldImage : oldImages) { oldImage.delete(); } try { file = File.createTempFile("instagram", ".png", parentDir); os = new FileOutputStream(file, true); } catch (Exception e) { e.printStackTrace(); } try { os.write(imageData); os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); shareIntent.putExtra(Intent.EXTRA_TEXT, captionString); shareIntent.setPackage("com.instagram.android"); this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345); } else { this.cbContext.error("Expected one non-empty string argument."); } }
From source file:com.tct.email.NotificationController.java
private static void refreshNotificationsForAccountInternal(final Context context, final long accountId) { final Uri accountUri = EmailProvider.uiUri("uiaccount", accountId); final ContentResolver contentResolver = context.getContentResolver(); final Cursor mailboxCursor = contentResolver.query( ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId), null, null, null, null);// w w w .ja va 2 s. co m try { while (mailboxCursor.moveToNext()) { final long mailboxId = mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN); if (mailboxId == 0) continue; final int unseenCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN); final int unreadCount; // If nothing is unseen, clear the notification if (unseenCount == 0) { unreadCount = 0; } else { unreadCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN); } //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247 ADD_S Mailbox mailbox = Mailbox.restoreMailboxWithId(context, mailboxId); //TS:kaifeng.lu 2015-12-18 EMAIL BUGFIX_1190892 MOD_S if (mailbox != null && mailbox.mType == Mailbox.TYPE_INBOX) { //TS:kaifeng.lu 2015-12-18 EMAIL BUGFIX_1190892 MOD_E final Cursor unreadCursor = contentResolver.query(ContentUris .withAppendedId(EmailContent.MAILBOX_MOST_RECENT_UNREAD_MESSAGE_URI, mailboxId), null, null, null, null); long mostRecentUnreadMsgId = 0; if (unreadCursor != null && unreadCursor.moveToFirst()) { try { mostRecentUnreadMsgId = unreadCursor .getLong(EmailContent.MAILBOX_MOST_RECENT_UNREAD_ID_COULUM); } finally { unreadCursor.close(); } } final int key = getUnreadKey(accountId, mailboxId); long lastMostRecentUnreadMsgId = sLastUnreadIds.get(key); LogUtils.i(LOG_TAG, "key=" + key + " unseenCount=" + unseenCount + " unreadCount=" + unreadCount + " lastMostRecentUnreadMsgId = " + lastMostRecentUnreadMsgId + " mostRecentUnreadMsgId=" + mostRecentUnreadMsgId); //no need to send notification if latest Unread id not change if (lastMostRecentUnreadMsgId != 0 && unseenCount != 0 && lastMostRecentUnreadMsgId == mostRecentUnreadMsgId) { LogUtils.i(LOG_TAG, "no need to send notification broadcast, continue"); continue; } sLastUnreadIds.put(key, mostRecentUnreadMsgId); } //TS:zheng.zou 2015-12-17 EMAIL BUGFIX_861247 ADD_E final Uri folderUri = EmailProvider.uiUri("uifolder", mailboxId); LogUtils.d(LOG_TAG, "Changes to account " + accountId + ", folder: " + mailboxId + ", unreadCount: " + unreadCount + ", unseenCount: " + unseenCount); final Intent intent = new Intent(UIProvider.ACTION_UPDATE_NOTIFICATION); intent.setPackage(context.getPackageName()); intent.setType(EmailProvider.EMAIL_APP_MIME_TYPE); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT, accountUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER, folderUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT, unreadCount); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT, unseenCount); context.sendOrderedBroadcast(intent, null); } } finally { mailboxCursor.close(); } }
From source file:com.chale22.ico01.fragments.FragmentTheme.java
private void applyNovaTheme() { WallpaperManager setDefaultWallpaper = WallpaperManager.getInstance(getActivity().getApplicationContext()); try {/*from ww w .j a v a2 s.c o m*/ Intent novalauncherIntent = new Intent(ACTION_APPLY_ICON_THEME); novalauncherIntent.setPackage(NOVA_PACKAGE); novalauncherIntent.putExtra(EXTRA_ICON_THEME_TYPE, "GO"); novalauncherIntent.putExtra(EXTRA_ICON_THEME_PACKAGE, getActivity().getPackageName()); startActivity(novalauncherIntent); } catch (ActivityNotFoundException e3) { e3.printStackTrace(); makeToast("Nova Launcher is not installed!"); } //finish(); }
From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java
private void addPendingIntents(RemoteViews rv, boolean isPlaying, MediaInfo info) { Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent); rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent); if (isPlaying) { if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark); } else {//from ww w.j a v a 2s .c o m rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark); } } else { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark); } }
From source file:com.google.fpl.gim.examplegame.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Utils.logDebug(TAG, "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Start service so it can run in bound and unbound state. Intent intent = new Intent(this, MainService.class); intent.setPackage(getPackageName()); startService(intent);//w ww . j av a2s . com // create new fragments and initialize data if (savedInstanceState == null) { mGameViews = new GameViews(); mGameViews.initializeFragments(this); } else { // restore old fragments and data mGameViews.restoreFragments(this); } displayHomeUp(canPressBackButton()); getFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { displayHomeUp(canPressBackButton()); } }); }
From source file:com.sdk.download.providers.downloads.DownloadNotification.java
private void updateActiveNotification(Collection<DownloadInfo> downloads) { // Collate the notifications mNotifications.clear();/*from ww w . j av a 2 s. c o m*/ for (DownloadInfo download : downloads) { if (!isActiveAndVisible(download)) { continue; } String packageName = download.mPackage; long max = download.mTotalBytes; long progress = download.mCurrentBytes; long id = download.mId; String title = download.mTitle; if (title == null || title.length() == 0) { title = mContext.getResources().getString(R.string.zuimeia_sdk_download_download_unknown_title); } synchronized (mNotifications) { if (!mNotifications.containsKey(id)) { if (download.mStatus == Downloads.STATUS_RUNNING) { NotificationItem item = new NotificationItem(); item.mId = id; item.mPackageName = packageName; item.mDescription = download.mDescription; item.mStatus = download.mStatus; item.addItem(title, progress, max); mNotifications.put(download.mId, item); if (download.mStatus == Downloads.STATUS_QUEUED_FOR_WIFI && item.mPausedText == null) { item.mPausedText = mContext.getResources() .getString(R.string.zuimeia_sdk_download_notification_need_wifi_for_size); } } else { mSystemFacade.cancelNotification(id); } } } } // Add the notifications for (NotificationItem item : mNotifications.values()) { // Build the notification object final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setPriority(2); boolean hasPausedText = (item.mPausedText != null); int iconResource = android.R.drawable.stat_sys_download_done; if (hasPausedText) { iconResource = android.R.drawable.stat_sys_warning; } builder.setSmallIcon(iconResource); builder.setOngoing(true); boolean hasContentText = false; StringBuilder title = new StringBuilder(item.mTitles[0]); if (item.mTitleCount > 1) { title.append(mContext.getString(R.string.zuimeia_sdk_download_notification_filename_separator)); title.append(item.mTitles[1]); if (item.mTitleCount > 2) { title.append(mContext.getString(R.string.zuimeia_sdk_download_notification_filename_extras, new Object[] { Integer.valueOf(item.mTitleCount - 2) })); } } else if (!TextUtils.isEmpty(item.mDescription)) { builder.setContentText(item.mDescription); hasContentText = true; } builder.setContentTitle(title);// if (hasPausedText) {// ?? builder.setContentText(item.mPausedText); } else { builder.setProgress((int) item.mTotalTotal, (int) item.mTotalCurrent, item.mTotalTotal == -1); if (Build.VERSION.SDK_INT >= 11) { if (hasContentText) { builder.setContentInfo(getDownloadingText(item.mTotalTotal, item.mTotalCurrent)); } } else {// ?android 3.0 builder.setContentText(String.format(mContext.getString(R.string.sdk_download_progress_percent), getDownloadingText(item.mTotalTotal, item.mTotalCurrent))); } } // ?() // if (item.mStatus == Downloads.STATUS_PENDING || item.mStatus == // Downloads.STATUS_RUNNING) { // Intent pauseIt = new // Intent(ZMDownloadReceiver.DOWNLOADRECEIVER_PAUSE); // pauseIt.setPackage(mContext.getPackageName()); // Bundle bundle = new Bundle(); // bundle.putLong(ZMDownloadReceiver.INTENT_DOWNLOAD_ID, item.mId); // bundle.putInt(ZMDownloadReceiver.INTENT_DOWNLOAD_STATUS, // item.mStatus); // pauseIt.putExtras(bundle); // builder.addAction(R.drawable.sdk_download_pause, // mContext.getString(R.string.zuimeia_sdk_download_notification_pause), // PendingIntent.getBroadcast(mContext, 0, pauseIt, // PendingIntent.FLAG_CANCEL_CURRENT)); // } // ? if (item.mStatus != Downloads.STATUS_SUCCESS) { Intent cancelIt = new Intent(DownloadReceiver.DOWNLOAD_CANCEL); cancelIt.setPackage(mContext.getPackageName()); Bundle bundle = new Bundle(); bundle.putLong(DownloadReceiver.INTENT_DOWNLOAD_ID, item.mId); bundle.putInt(DownloadReceiver.INTENT_DOWNLOAD_STATUS, item.mStatus); cancelIt.putExtras(bundle); builder.addAction(R.drawable.sdk_download_download_cancel, mContext.getString(R.string.sdk_download_notification_cancel), PendingIntent.getBroadcast(mContext, 0, cancelIt, PendingIntent.FLAG_CANCEL_CURRENT)); } Intent intent = new Intent(Constants.ACTION_LIST); intent.setClassName(mContext, DownloadReceiver.class.getName()); intent.setData(ContentUris.withAppendedId(Downloads.getAllDownloadsContentURI(mContext), item.mId)); intent.putExtra("multiple", item.mTitleCount > 1); builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0)); mSystemFacade.postNotification(item.mId, builder.build()); } }
From source file:de.vanita5.twittnuker.fragment.support.AbsStatusesFragment.java
@Override public void onStatusActionClick(StatusViewHolder holder, int id, int position) { final ParcelableStatus status = mAdapter.getStatus(position); if (status == null) return;//from w ww .j a v a 2 s .c om switch (id) { case R.id.reply_count: { final Context context = getActivity(); final Intent intent = new Intent(INTENT_ACTION_REPLY); intent.setPackage(context.getPackageName()); intent.putExtra(EXTRA_STATUS, status); context.startActivity(intent); break; } case R.id.retweet_count: { RetweetQuoteDialogFragment.show(getFragmentManager(), status); break; } case R.id.favorite_count: { final AsyncTwitterWrapper twitter = getTwitterWrapper(); if (twitter == null) return; if (status.is_favorite) { twitter.destroyFavoriteAsync(status.account_id, status.id); } else { twitter.createFavoriteAsync(status.account_id, status.id); } break; } } }
From source file:me.henrytao.bootstrapandroidlibrarydemo.activity.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDonateItems = getResources().getStringArray(R.array.donate_items); Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE); }