使用sqlite数据库在android中获取推送通知

时间:2014-04-11 04:59:52

标签: android sqlite push-notification titanium

如何使用钛在Android上午8:00将消息作为推送通知?该消息已存储在SQLite数据库中。

2 个答案:

答案 0 :(得分:0)

从db获取您的消息并通知

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
 import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.Menu;

public class MainActivity extends Activity {

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    showNotification("This is My Text");

}
private void showNotification(String message) {
    // In this sample, we'll use the same text for the ticker and the expanded notification
    CharSequence text =message;

    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.ic_launcher, text,
            System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);
    //  PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0,
    //      new Intent(),PendingIntent.FLAG_UPDATE_CURRENT);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, message,
                   text, contentIntent);
     NotificationManager mNM;
     mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
     int NOTIFICATION = 0;
     // Send the notification.
    mNM.notify(NOTIFICATION, notification);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
 }

}

答案 1 :(得分:0)

尝试此模块以获取本地通知。

https://github.com/benbahrenburg/benCoding.AlarmManager