I know there are a lot of them, but I tried all the time and Iβm not going anywhere. None of the examples in google docs, none of the 5 other ways that I found here worked for me at all. As in the typical case, when I press the notification, it closes the status bar and nothing is displayed on the screen. I am creating a notification from a service and need a notification to initiate a new action that has not yet been created. I will also need a way to convey information to this activity through intent.
And yes ... it's Java for Android
What follows is the broken remains of my code.
package com.bobbb.hwk2;
import java.io.FileOutputStream;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.widget.Toast;
public class contactBackup extends Service
{
private NotificationManager nManager;
private static final int NOTIFY_ID = 1100;
@Override
public void onCreate()
{
super.onCreate();
String ns = Context.NOTIFICATION_SERVICE;
nManager = (NotificationManager)getSystemService(ns);
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(getApplicationContext(), R.string.service_started,Toast.LENGTH_LONG).show();
String data = lookUpContacts();
if( saveToSDCard(getResources().getString(R.string.backup_file_name),data) )
{
Context context = getApplicationContext();
Intent nIntent = new Intent(this,contactViewer.class);
nIntent.setClass(context,contactViewer.class);
Notification msg = new Notification(R.drawable.icon,"All contacts records have been written to the file.",System.currentTimeMillis());
PendingIntent pIntent = PendingIntent.getActivity(this,0,nIntent,0);
msg.flags = Notification.FLAG_AUTO_CANCEL;
msg.setLatestEventInfo(context,
"success",
"All contacts records have been written to the file.",
pIntent);
nManager.notify(NOTIFY_ID,msg);
}
}
@Override
public void onDestroy()
{
nManager.cancel(NOTIFY_ID);
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
public String lookUpContacts()
{
...
}
public boolean saveToSDCard(String fileName, String data)
{
...
}
}
, , , - - , , ( -): U)
, .
, , , ,
: D