下面列出了android.content.Intent#putExtras ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void sendSuggestionIntent(ResultItem item) {
try {
Intent sendIntent = new Intent(this, Class.forName(searchableActivity));
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle b = new Bundle();
b.putParcelable(CustomSearchableConstants.CLICKED_RESULT_ITEM, item);
sendIntent.putExtras(b);
startActivity(sendIntent);
finish();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void turnAlarm(AlarmInfo alarmInfo,String AlarmID,Boolean isOn){
if(alarmInfo==null){
Log.d("alarm","传入AlarmInfo不为空");
alarmInfo=dao.findById(AlarmID);
}
this.alarmInfo=alarmInfo;
AlarmManager mAlamManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int id=dao.getOnlyId(alarmInfo);
Intent intent = new Intent(context, AlarmReciver.class);
Bundle bundle=new Bundle();
bundle.putSerializable("alarminfo", alarmInfo);
intent.putExtras(bundle);
intent.setAction("com.Joe.RING_ALARM");
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.putExtra("alarmid", id);
intent.putExtra("cancel",false);
intent.putExtra("getid",alarmInfo.getId());
Log.d("alarm", "id" + id);
//每个闹钟不同的pi
PendingIntent pi= PendingIntent.getBroadcast(context,id, intent,PendingIntent.FLAG_UPDATE_CURRENT);
if(isOn){
startAlarm(mAlamManager,pi);
}else{
cancelAlarm(intent);
}
}
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
Log.i(TAG, "Action received: " + action);
Intent activity = new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
if (action.equals("com.androzic.COORDINATES_RECEIVED"))
{
activity.putExtras(intent);
activity.putExtra(MainActivity.SHOW_FRAGMENT, CoordinatesReceived.class);
}
if (action.equals("com.androzic.CENTER_ON_COORDINATES"))
{
activity.putExtras(intent);
}
context.startActivity(activity);
}
private void handleMessageWithTemplate( final Context context, Intent intent, AndroidPushTemplate androidPushTemplate, final int notificationId )
{
Bundle newBundle = PushTemplateHelper.prepareMessageBundle( intent.getExtras(), androidPushTemplate, notificationId );
Intent newMsgIntent = new Intent();
newMsgIntent.putExtras( newBundle );
if( !this.onMessage( context, newMsgIntent ) )
return;
if( androidPushTemplate.getContentAvailable() != null && androidPushTemplate.getContentAvailable() == 1 )
return;
Notification notification = PushTemplateHelper.convertFromTemplate( context, androidPushTemplate, newBundle, notificationId );
PushTemplateHelper.showNotification( context, notification, androidPushTemplate.getName(), notificationId );
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, SignaturePickerActivity.class);
intent.putExtras(getIntent().getExtras());
startActivityForResult(intent, RC_SIGANTURE_PICKER);
}
/**
* Classes wishing to access the email sending functionality should pass an
* intent constructed with the following action and extras.
* <p>
* recipient addresses:
* Intent.EXTRA_EMAIL, String[]
* subject:
* Intent.EXTRA_SUBJECT, String
* text:
* Intent.EXTRA_TEXT, CharSequence
* attachments:
* Intent.EXTRA_STREAM, List<Uri> or Uri
*/
protected void onHandleIntent(Intent intent) {
try {
// TODO Auto-generated method stub
final Intent mailer = new Intent(Intent.ACTION_SEND);
mailer.setType("message/rfc822");
mailer.putExtras(intent);
mailer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//TODO Success status?
startActivity(mailer);
sendBroadcast(new Intent(SENT));
} catch (Exception e) {
sendBroadcast(new Intent(FAILED));
}
}
public static void showImage(@NonNull Context context, @NonNull String title,
@NonNull String imageUrl){
Intent intent = new Intent(context, ViewerActivity.class);
intent.putExtras(BundleHelper.builder().put("viewerType", ViewerType.Image)
.put("title", title).put("imageUrl", imageUrl).build());
context.startActivity(intent);
}
public static void startActivityForResult(Activity activity, String action, Bundle bundle, int result) {
if (!DoubleClickUtil.isFastDoubleClick())
return;
Intent intent = new Intent();
intent.setAction(action);
if (bundle != null) {
intent.putExtras(bundle);
}
activity.startActivityForResult(intent, result);
}
@Override
public void onClick(View v) {
Intent i = new Intent(c, ArmorDetailActivity.class);
i.putExtra(ArmorDetailActivity.EXTRA_ARMOR_ID, id);
// If we are being called by something else
if (activity != null) {
i.putExtras(activity.getIntent().getExtras());
activity.startActivityForResult(i, requestCode);
}
else {
c.startActivity(i);
}
}
private void showConfirmationDialog(String title, String message, String actionstring) {
Intent intent = new Intent(this, AcceptActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle params = new Bundle();
params.putString("title", title);
params.putString("message", message);
params.putString("actionstring", actionstring);
intent.putExtras(params);
startActivity(intent);
}
/**
* startActivityForResult with bundle
*
* @param clazz
* @param requestCode
* @param bundle
*/
protected void readyGoForResult(Class<?> clazz, int requestCode, Bundle bundle) {
Intent intent = new Intent(this, clazz);
if (null != bundle) {
intent.putExtras(bundle);
}
startActivityForResult(intent, requestCode);
}
@Override
protected void onProgressUpdate(Video... values) {
super.onProgressUpdate(values);
Intent i = new Intent(Constants.VIDEO_UPDATE_ACTION);
Bundle bundle = new Bundle();
bundle.putSerializable(Constants.VIDEO, values[0]);
i.putExtras(bundle);
mContext.sendBroadcast(i);
}
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null) {
Log.e("Received a null intent.");
return;
}
// Parse manifest and pull metadata which contains client broadcast receiver class.
String receiver = LeanplumManifestHelper.parseNotificationMetadata();
// If receiver isn't found we will open up notification with default activity
if (receiver == null) {
Log.d("Custom broadcast receiver class not set, using default one.");
LeanplumPushService.openNotification(context, intent);
} else {
Log.d("Custom broadcast receiver class found, using it to handle push notifications.");
// Forward Intent to a client broadcast receiver.
Intent forwardIntent = new Intent();
// Add action to be able to differentiate between multiple intents.
forwardIntent.setAction(LeanplumPushService.LEANPLUM_NOTIFICATION);
forwardIntent.setClassName(context, receiver);
forwardIntent.putExtras(intent.getExtras());
context.sendBroadcast(forwardIntent);
}
} catch (Throwable t) {
Util.handleException(t);
}
Leanplum.countAggregator().incrementCount("did_receive_remote_notification");
}
/**
* 跳转到activity,并附带bundle
*
* @param clazz Activity
* @param extras 附带Bundle
*/
protected void openActivity(Class<?> clazz, Bundle extras) {
Intent intent = new Intent(getActivity(), clazz);
if (extras != null) {
intent.putExtras(extras);
}
startActivity(intent);
}
/**
* 启动视频播放页面
*
* @param context
* @param bundle
*/
public static void startPictureVideoPlayActivity(Context context, Bundle bundle, int requestCode) {
if (!DoubleUtils.isFastDoubleClick()) {
Intent intent = new Intent();
intent.setClass(context, PictureVideoPlayActivity.class);
intent.putExtras(bundle);
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
((Activity) context).startActivityForResult(intent, requestCode);
}
}
}
/**
* [含有Bundle通过Class打开编辑界面]
*
* @param cls
* @param bundle
* @param requestCode
*/
public void startActivityForResult(Class<?> cls, Bundle bundle,
int requestCode) {
Intent intent = new Intent();
intent.setClass(this, cls);
if (bundle != null) {
intent.putExtras(bundle);
}
startActivityForResult(intent, requestCode);
}
private static void exit(@NonNull Context context, @NonNull Class<?> cls) {
Intent intent = new Intent(context, cls);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
bundle.putBoolean(TAG_EXIT, true);
intent.putExtras(bundle);
context.startActivity(intent);
}
private void launch() {
Intent intent = new Intent(this, NavigationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (getIntent().getExtras() != null) {
intent.putExtras(getIntent().getExtras());
}
startActivity(intent);
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
public static void openClassResult(Context mContext, Class<?> cls,int requestCode,Bundle bundle){
Intent q=new Intent(mContext,cls);
q.putExtras(bundle);
((Activity)mContext).startActivityForResult(q,requestCode);
}
/**
* The intent to launch the Activity.
*
* @param targetPackage The package of the Activity.
* @param activityClass The Activity class send the intent to.
* @param bundleCreator Bundle creator instance that will give a bundle to the activity.
* @param <T> The specific Activity type.
* @return The intent to start the activity.
*/
protected <T extends Activity> Intent getLaunchIntent(String targetPackage,
Class<T> activityClass, BundleCreator bundleCreator) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(targetPackage, activityClass.getName());
intent.putExtras(bundleCreator.createBundle());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}