下面列出了android.content.Intent#removeExtra ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_contact_activity);
attachXml();
contentResolver = getContentResolver();
layoutInflater = getLayoutInflater();
final Intent callingIntent = getIntent();
viaId = callingIntent.hasExtra(CONTACT_ID);
contactKeyExtra =
viaId ?
callingIntent.getStringExtra(CONTACT_ID)
:
callingIntent.getStringExtra(CONTACT_LOOKUP_KEY)
;
callingIntent.removeExtra(PIC_URI_EXTRA);
}
synchronized public boolean stop() {
try {
Intent serviceIntent = StaticData.getRunningIntentByName(getWrapperName());
if (serviceIntent != null) {
serviceIntent.removeExtra("tinygsn.beans.config");
config.setRunning(false);
Bundle bundle = new Bundle();
bundle.putParcelable("tinygsn.beans.config", config);
serviceIntent.putExtra("tinygsn.beans.config", bundle);
StaticData.globalContext.startService(serviceIntent);
StaticData.IntentStopped(getWrapperName());
return true;
}
} catch (Exception e) {
// release anything?
}
return false;
}
/**
* Converts a fragment arguments bundle into an intent.
*/
public static Intent fragmentArgumentsToIntent(Bundle arguments) {
Intent intent = new Intent();
if (arguments == null) {
return intent;
}
final Uri data = arguments.getParcelable("_uri");
if (data != null) {
intent.setData(data);
}
intent.putExtras(arguments);
intent.removeExtra("_uri");
return intent;
}
/**
* 指定されたリクエストからイベントセッションの登録・解除の処理を行います.
*
* @param request リクエスト
* @param dest 送信先のプラグイン
*/
public void parseEventSession(final Intent request, final DevicePlugin dest) {
String serviceId = DConnectProfile.getServiceID(request);
String origin = request.getStringExtra(IntentDConnectMessage.EXTRA_ORIGIN);
if (serviceId == null) {
return;
}
String accessToken = getAccessToken(origin, serviceId);
if (accessToken != null) {
request.putExtra(DConnectMessage.EXTRA_ACCESS_TOKEN, accessToken);
} else {
request.removeExtra(DConnectMessage.EXTRA_ACCESS_TOKEN);
}
if (isRegistrationRequest(request)) {
registerRequest(request, dest);
} else if (isUnregistrationRequest(request)) {
unnregisterRequest(request, dest);
}
}
/**
* 通常是在 onNewIntent 调用,用于解析二级跳转
*/
public static void inject(Activity activity, Intent intent) {
try {
inject(activity, intent.getExtras(), intent.getData());
} catch (Exception e) {
LoggerUtils.handleException(e);
}
// 解析二级跳转
GActivityBuilder activityBuilder = getNextNav(intent);
if (activityBuilder == null) {
return;
}
activityBuilder.start(activity);
// 删除二级跳转信息,避免重复跳转
intent.removeExtra(GActivityBuilder.NEXT_NAV_ACTIVITY_BUILDER);
}
/**
* Converts a fragment arguments bundle into an intent.
*/
public static Intent fragmentArgumentsToIntent(final Bundle arguments) {
final Intent intent = new Intent();
if (arguments == null) {
return intent;
}
final Uri data = arguments.getParcelable("_uri");
if (data != null) {
intent.setData(data);
}
intent.putExtras(arguments);
intent.removeExtra("_uri");
return intent;
}
@Override
public void startActivity(Intent intent) {
if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
}
try {
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(this, R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device, Toast.LENGTH_LONG).show();
}
}
/**
* 将 intent 的 extras 合并到 originIntent 的 extras
*
* @param intent The intent
* @param pluginClassLoader 插件的 {@link ClassLoader}
*/
public static void mergeIntentExtras(Intent intent, ClassLoader pluginClassLoader) {
Intent originIntent = intent.getParcelableExtra(Constants.ORIGIN_INTENT);
if (null == originIntent) {
return;
}
ComponentName hostComponent = intent.getComponent();
intent.setComponent(originIntent.getComponent());
intent.putExtra(Constants.HOST_COMPONENT, hostComponent);
intent.removeExtra(Constants.ORIGIN_INTENT);
originIntent.setExtrasClassLoader(pluginClassLoader);
mergeExtras(intent, originIntent);
intent.setExtrasClassLoader(pluginClassLoader);
}
private void postCleanup() {
if (mLauncher != null) {
// Remove any drag params from the launcher intent since the drag operation is complete.
Intent newIntent = new Intent(mLauncher.getIntent());
newIntent.removeExtra(EXTRA_PIN_ITEM_DRAG_LISTENER);
mLauncher.setIntent(newIntent);
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
removeListener();
}
});
}
private Intent handleInstallShortcutIntent(Intent intent) {
Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (shortcut != null) {
ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
if (component != null) {
String pkg = component.getPackageName();
Intent newShortcutIntent = new Intent();
newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);
Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
try {
Resources resources = VirtualCore.get().getResources(pkg);
if (resources != null) {
int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
if (resId > 0) {
Drawable iconDrawable = resources.getDrawable(resId);
Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
if (newIcon != null) {
intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
return intent;
}
private void handleUninstallShortcutIntent(Intent intent) {
Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (shortcut != null) {
ComponentName componentName = shortcut.resolveActivity(getPM());
if (componentName != null) {
Intent newShortcutIntent = new Intent();
newShortcutIntent.putExtra("_VA_|_uri_", shortcut);
newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
newShortcutIntent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);
}
}
}
@Override
protected void onStart() {
super.onStart();
final Intent intent = getIntent();
if (!isDeviceConnected() && intent.hasExtra(FeaturesActivity.EXTRA_ADDRESS)) {
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(getIntent().getByteArrayExtra(FeaturesActivity.EXTRA_ADDRESS));
onDeviceSelected(device, device.getName());
intent.removeExtra(FeaturesActivity.EXTRA_APP);
intent.removeExtra(FeaturesActivity.EXTRA_ADDRESS);
}
}
@Override
public boolean onRequest(final Intent request, final Intent response) {
String uri = request.getStringExtra(PARAM_URI);
if (uri != null) {
if (uri.startsWith("content://")) {
byte[] data = getContentData(uri);
request.putExtra(PARAM_DATA, data);
request.removeExtra(PARAM_URI);
}
}
return super.onRequest(request, response);
}
/**
* In the case where Chrome is called through the fallback mechanism from Instant Apps,
* record the amount of time the whole trip took and which UI took the user back to Chrome,
* if any.
* @param intent The current intent.
*/
private void maybeRecordFallbackStats(Intent intent) {
Long startTime = IntentUtils.safeGetLongExtra(intent, INSTANT_APP_START_TIME_EXTRA, 0);
if (startTime > 0) {
sFallbackIntentTimes.record(SystemClock.elapsedRealtime() - startTime);
intent.removeExtra(INSTANT_APP_START_TIME_EXTRA);
}
int callSource = IntentUtils.safeGetIntExtra(intent, BROWSER_LAUNCH_REASON, 0);
if (callSource > 0 && callSource < SOURCE_BOUNDARY) {
sFallbackCallSource.record(callSource);
intent.removeExtra(BROWSER_LAUNCH_REASON);
} else if (callSource >= SOURCE_BOUNDARY) {
Log.e(TAG, "Unexpected call source constant for Instant Apps: " + callSource);
}
}
/**
* Just like {@link Intent#removeExtra(String)} but doesn't throw exceptions.
*/
public static void safeRemoveExtra(Intent intent, String name) {
try {
intent.removeExtra(name);
} catch (Throwable t) {
// Catches un-parceling exceptions.
Log.e(TAG, "removeExtra failed on intent " + intent);
}
}
public void parseBootIntent() {
try {
Intent intent = TiApplication.getAppRootOrCurrentActivity().getIntent();
String notification = intent.getStringExtra(INTENT_EXTRA);
if (notification != null) {
sendMessage(notification, true);
intent.removeExtra(INTENT_EXTRA);
} else {
Log.d(LCAT, "Empty notification in Intent");
}
} catch (Exception ex) {
Log.e(LCAT, "parseBootIntent" + ex);
}
}
@Override
public void startActivity(Intent intent) {
if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
}
try {
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG, e);
Toast.makeText(this, R.string.no_app_to_handle_data, Toast.LENGTH_LONG).show();
}
}
@Override
public void onResume(){
super.onResume();
// Resume the search view with the last keyword
if(mSearchView != null) {
mSearchView.post(new Runnable() {
@Override
public void run() {
mSearchView.setQuery(mSearchKeyWord, true);
}
});
}
toolbar.setNavigationIcon(R.drawable.drawer_icon);
toolbar.setBackgroundColor(getResources().getColor(R.color.theme_default_primary));
Utils.setToolbarTextAndIconColor(activity, toolbar,true);
//displayBlankFragment();
Intent startIntent = getActivity().getIntent();
String email = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_EMAIL);
String rootFolder = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER);
//if called from the widget
String notebookName = startIntent.getStringExtra(Utils.SELECTED_NOTEBOOK_NAME);
String tagName = startIntent.getStringExtra(Utils.SELECTED_TAG_NAME);
ActiveAccount activeAccount;
if(email != null && rootFolder != null) {
activeAccount = activeAccountRepository.switchAccount(email,rootFolder);
//remove the values because if one selects an other account and then goes into detail an then back, the values will be present, in phone mode
startIntent.removeExtra(Utils.INTENT_ACCOUNT_EMAIL);
startIntent.removeExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER);
}else{
activeAccount = activeAccountRepository.getActiveAccount();
}
//if called from the widget
if(notebookName != null){
Utils.setSelectedNotebookName(activity, notebookName);
Utils.setSelectedTagName(activity,null);
}else if(tagName != null){
Utils.setSelectedNotebookName(activity, null);
Utils.setSelectedTagName(activity,tagName);
}
String selectedNotebookName = Utils.getSelectedNotebookName(activity);
final String nameOfActiveAccount = Utils.getNameOfActiveAccount(activity, activeAccount.getAccount(), activeAccount.getRootFolder());
mDrawerAccountsService.changeSelectedAccount(activity, nameOfActiveAccount, activeAccount.getAccount(), Utils.getAccountType(activity, activeAccount));
if(initPhase){
initPhase = false;
return;
}
if(selectedNotebookName != null) {
Notebook nb = notebookRepository.getBySummary(activeAccount.getAccount(), activeAccount.getRootFolder(), selectedNotebookName);
//GitHub Issue 31
if (nb != null) {
notebookName = nb.getIdentification().getUid();
}
}
//Refresh the loaded data because it could be that something changed, after coming back from detail activity
new AccountChangeThread(activeAccount,notebookName).run();
}
/** Serialize a Favorite for persistence, including a checksum wrapper. */
private Favorite packFavorite(Cursor c) {
Favorite favorite = new Favorite();
favorite.id = c.getLong(ID_INDEX);
favorite.screen = c.getInt(SCREEN_INDEX);
favorite.container = c.getInt(CONTAINER_INDEX);
favorite.cellX = c.getInt(CELLX_INDEX);
favorite.cellY = c.getInt(CELLY_INDEX);
favorite.spanX = c.getInt(SPANX_INDEX);
favorite.spanY = c.getInt(SPANY_INDEX);
favorite.iconType = c.getInt(ICON_TYPE_INDEX);
if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) {
String iconPackage = c.getString(ICON_PACKAGE_INDEX);
if (!TextUtils.isEmpty(iconPackage)) {
favorite.iconPackage = iconPackage;
}
String iconResource = c.getString(ICON_RESOURCE_INDEX);
if (!TextUtils.isEmpty(iconResource)) {
favorite.iconResource = iconResource;
}
}
if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) {
byte[] blob = c.getBlob(ICON_INDEX);
if (blob != null && blob.length > 0) {
favorite.icon = blob;
}
}
String title = c.getString(TITLE_INDEX);
if (!TextUtils.isEmpty(title)) {
favorite.title = title;
}
String intentDescription = c.getString(INTENT_INDEX);
if (!TextUtils.isEmpty(intentDescription)) {
try {
Intent intent = Intent.parseUri(intentDescription, 0);
intent.removeExtra(ItemInfo.EXTRA_PROFILE);
favorite.intent = intent.toUri(0);
} catch (URISyntaxException e) {
Log.e(TAG, "Invalid intent", e);
}
}
favorite.itemType = c.getInt(ITEM_TYPE_INDEX);
if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) {
favorite.appWidgetId = c.getInt(APPWIDGET_ID_INDEX);
String appWidgetProvider = c.getString(APPWIDGET_PROVIDER_INDEX);
if (!TextUtils.isEmpty(appWidgetProvider)) {
favorite.appWidgetProvider = appWidgetProvider;
}
}
return favorite;
}
public void fireAlarm(@Nullable Intent intent) throws InterruptedException {
Context c = App.get();
if ((intent == null) || !intent.hasExtra(EXTRA_ALARMID)) {
return;
}
int alarmId = intent.getIntExtra(EXTRA_ALARMID, 0);
long time = intent.getLongExtra(EXTRA_TIME, 0);
Alarm alarm = Alarm.fromId(alarmId);
if (alarm == null || !alarm.isEnabled())
return;
intent.removeExtra(EXTRA_ALARMID);
Times t = alarm.getCity();
if (t == null)
return;
int notId = t.getIntID();
NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_TAG, notId);
alarm.vibrate(c);
final MyPlayer player = MyPlayer.from(alarm);
if (player != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground(getClass().hashCode(), AlarmUtils.buildPlayingNotification(c, alarm, time));
} else {
nm.notify(NOTIFICATION_TAG, notId, AlarmUtils.buildPlayingNotification(c, alarm, time));
}
if (Preferences.SHOW_NOTIFICATIONSCREEN.get()) {
NotificationPopup.start(c, alarm);
Thread.sleep(1000);
}
try {
player.play();
if (Preferences.STOP_ALARM_ON_FACEDOWN.get()) {
StopByFacedownMgr.start(this, player);
}
sInterrupt.set(false);
while (!sInterrupt.get() && player.isPlaying()) {
Thread.sleep(500);
}
if (player.isPlaying()) {
player.stop();
}
} catch (Exception e) {
Crashlytics.logException(e);
}
nm.cancel(NOTIFICATION_TAG, notId);
if (NotificationPopup.instance != null && Preferences.SHOW_NOTIFICATIONSCREEN.get()) {
NotificationPopup.instance.finish();
}
}
if (!alarm.isRemoveNotification() || player == null) {
Notification not = AlarmUtils.buildAlarmNotification(c, alarm, time);
nm.notify(NOTIFICATION_TAG, notId, not);
}
if (alarm.getSilenter() != 0) {
SilenterReceiver.silent(c, alarm.getSilenter());
}
}