• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Tutorial/skill level required/already existing app? - pop-up texts at set time frequency

Benjimanz

Lurker
Hi,
So, I want an app where I store different texts, which then later pops up when I want, like every 24hr or every morning. I would like to make this app myself because I want it simple and to understand it completely.

I am not new to programming, but I don't know this language. Do you think this would be hard for me, to create this app, but with "full guidance", or is it better to leave it to someone who will create it for me, or maybe there is an already existing simple app like this one.

Thanks

Benji
 
It it not so hard to do. The things you need to read up on to get this working would be:
1. Android Preferences. You can use these to let the user choose what time frequency he/she wants: Android Preferences | Kaloer.com

2. SQLite database. To store the different texts you would like to have popping out: Android Tutorial For Beginners : Android SQLite Database Example Tutorial

3. AlarmManager. This class controls and can add/remove an alarm you specify to go off when you want and to do what you want: Android - Creating an Alarm with AlarmManager | Michael Irwin - Web Developer
 
Hi again,
I can't get the AlarmManager to work. I tried to make it as a separate project but it shows a lot of errors. What I did basically was to create a "AlarmRecieverActivity.java" and a "MainActivity.java" class, and then put the code in them. In res/layout I created the "alarm.xml" and the "main.xml" and pasted the "right" code in them aswell. I am getting errors from all things except from the alarm.xml.

Can you see any obvious mistakes I have done? Would be grateful if you helped me with this!
 
MainActivity - 12 errors.
Code:
package com.example.worldcountriesbooks;


public class AlarmMainActivity extends Activity {
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);
       setContentView(R.layout.main);
         
        //Create an offset from the current time in which the alarm will go off.
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, 5);
 
        //Create a new PendingIntent and add it to the AlarmManager
        Intent intent = new Intent(this, AlarmReceiverActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,
            12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am = 
            (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                pendingIntent);
    }
}
AlarmReceiverActivity - more than 20 errors..
Code:
package com.example.worldcountriesbooks;


public class AlarmReceiverActivity extends Activity {
    private MediaPlayer mMediaPlayer;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.alarm);
 
        Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
        stopAlarm.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View arg0, MotionEvent arg1) {
                mMediaPlayer.stop();
                finish();
                return false;
            }
        });
 
        playSound(this, getAlarmUri());
    }
 
    private void playSound(Context context, Uri alert) {
        mMediaPlayer = new MediaPlayer();
        try {
            mMediaPlayer.setDataSource(context, alert);
            final AudioManager audioManager = (AudioManager) context
                    .getSystemService(Context.AUDIO_SERVICE);
            if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
            }
        } catch (IOException e) {
            System.out.println("OOPS");
        }
    }
 
        //Get an alarm sound. Try for an alarm. If none set, try notification,
        //Otherwise, ringtone.
    private Uri getAlarmUri() {
        Uri alert = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_ALARM);
        if (alert == null) {
            alert = RingtoneManager
                    .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            if (alert == null) {
                alert = RingtoneManager
                        .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            }
        }
        return alert;
    }
}
main.xml - One error inr orw 9.
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:id="@+id/test"
    />
</LinearLayout>
alarm.xml - One exclamation error row 5.
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button android:text="Stop Alarm" android:id="@+id/stopAlarm"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
Do you need more information?
 
Back
Top Bottom