재 작성
우리는 당신이 Notifcation의 tickerText
단어에 랩을 강제하려는 전에 설명한 것처럼. 한 가지 방법은 적절한 길이의 줄에 텍스트를 깨고에 대한 통지를 보내 각 하나 나는 이의 길이를 가정 : 당신은 내가 설정 한의 불가분의 일부를 생략 볼 수 있습니다 그러나
public class Example extends Activity {
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.v("Example", "Alarm received");
sendNotification();
}
}
AlarmManager alarmManager;
NotificationManager notificationManager;
AlarmReceiver alarmReceiver = new AlarmReceiver();
Notification notification = new Notification();
Intent notificationIntent;
PendingIntent pendingIntent;
int tickerIndex = 0;
List<String> tickerTexts = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Determine the screen width and density, split tickerText appropriately
String tickerText = "A tickerText that is long enough to cause a word wrap in portrait.";
tickerTexts.add(tickerText.substring(0, 35));
tickerTexts.add(tickerText.substring(35));
notificationIntent = new Intent(this, Example.class);
pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
notification.icon = android.R.drawable.star_on;
sendNotification();
registerReceiver(alarmReceiver, new IntentFilter("Generic"));
}
@Override
protected void onDestroy() {
unregisterReceiver(alarmReceiver);
super.onDestroy();
}
public void sendNotification() {
Log.v("Example", "Send Notification " + tickerIndex);
notification.tickerText = tickerTexts.get(tickerIndex);
notification.setLatestEventInfo(this, "Title", "Text " + tickerIndex, pendingIntent);
notificationManager.cancel(0);
notificationManager.notify(0, notification);
tickerIndex++;
if(tickerIndex < tickerTexts.size()) {
Log.v("Example", "Setting up alarm");
PendingIntent alarmPending = PendingIntent.getBroadcast(this, 0, new Intent("Generic"), 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, alarmPending);
}
}
}
나는 맞는 텍스트를 계산하지 않았다. 적절한 중단 점을 결정하려면 화면 너비, 글꼴의 크기 조절 된 크기 및 밀도를 계산해야합니다. 당신은 또한 "!!!" 글꼴에 따라 "www"보다 짧을 수도 있고 사용자가 가로와 세로 사이를 전환 할 수도 있습니다 ... 소스 코드에서 일반적인 Android가 tickerText를 분해하는 방법을 살펴볼 수 있습니다.
어쨌든 tickerText를 자동 줄 바꿈으로 변경하는 것은 원래 String을 압축하거나 "비 포장"전화 제조업체에 분노한 편지를 보내는 것보다 훨씬 복잡 할 수 있습니다.
출처
2012-07-22 18:31:16
Sam
샘 (sam) 감사합니다. 훌륭한 답변 인 것처럼 보이지만, 실제로 필요한 것은 도움이되지 않습니다. 내 알림을 남겨 두지 않고 있습니다. 이벤트가 발생했을 때 깜박일뿐입니다. 나를 위해 일하지 마라. 내가 너무 길어서 알림을 원하지 않는다는 것에 동의한다. 나는 1-2 단어를 놓치고있다. ... – raingod
"깜박이는"것은 상태 표시 줄의'tickerText'를 의미한다. 또는 내가 이미지를 얻을 수 있다면 두 번)? – Sam
예, 정확하게. 그게 바로 끊어지고있는 .. – raingod