如果我有班级A.java
:
@JacksonXmlRootElement(localName = "A")
public class A {
}
产生的输出是:
<A
xmlns="">
我想在输出中添加一些名称空间,即
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com example.xsd"
如何配置A.java
以包含更多这样的自定义命名空间?
答案 0 :(得分:0)
由于xsi:schemaLocation是一个属性,因此可以这样添加它:
public class UIExampleReceiver extends BroadcastReceiver {
public static final String TAG_NOTIFICATION = "NOTIFICATION_MESSAGE";
public static final String CHANNEL_ID = "channel_1111";
public static final int NOTIFICATION_ID = 111111;
private static final String TAG = "Receiver";
@Override
public void onReceive(Context context, Intent intent) {
try {
// If android 10 or higher
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P)
{
startActivityNotification(context,NOTIFICATION_ID,context.getResources().getString(R.string.open_app), context.getResources().getString(R.string.click_app));
}
else
{
// If lower than Android 10, we use the normal method ever.
Intent activity = new Intent(context, ExampleActivity.class);
activity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
}
} catch (Exception e)
{
Log.d(TAG,e.getMessage()+"");
}
}
// notification method to support opening activities on Android 10
public static void startActivityNotification(Context context, int notificationID,
String title, String message) {
NotificationManager mNotificationManager =
(NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
//Create GPSNotification builder
NotificationCompat.Builder mBuilder;
//Initialise ContentIntent
Intent ContentIntent = new Intent(context, ExampleActivity.class);
ContentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent ContentPendingIntent = PendingIntent.getActivity(context,
0,
ContentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setColor(context.getResources().getColor(R.color.colorPrimaryDark))
.setAutoCancel(true)
.setContentIntent(ContentPendingIntent)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID,
"Activity Opening Notification",
NotificationManager.IMPORTANCE_HIGH);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mChannel.setDescription("Activity opening notification");
mBuilder.setChannelId(CHANNEL_ID);
Objects.requireNonNull(mNotificationManager).createNotificationChannel(mChannel);
}
Objects.requireNonNull(mNotificationManager).notify(TAG_NOTIFICATION,notificationID,
mBuilder.build());
}
}
它为我完成了工作。