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


  1. Benjimanz

    Benjimanz New Member

    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

    Advertisement
    :
  2. miXer

    miXer Well-Known Member

    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
  3. Benjimanz

    Benjimanz New Member

    Thanks, I'm looking in to it and will probably return here.
  4. Benjimanz

    Benjimanz New Member

    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!
  5. miXer

    miXer Well-Known Member

    Can you post your code in code tags here so i can take a look?!
  6. Benjimanz

    Benjimanz New Member

    MainActivity - 12 errors.
    Code (Text):
    1. package com.example.worldcountriesbooks;
    2.  
    3.  
    4. public class AlarmMainActivity extends Activity {
    5.      
    6.     @Override
    7.     public void onCreate(Bundle savedInstanceState) {
    8.         super.onCreate(savedInstanceState);
    9.             this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    10.        setContentView(R.layout.main);
    11.          
    12.         //Create an offset from the current time in which the alarm will go off.
    13.         Calendar cal = Calendar.getInstance();
    14.         cal.add(Calendar.SECOND, 5);
    15.  
    16.         //Create a new PendingIntent and add it to the AlarmManager
    17.         Intent intent = new Intent(this, AlarmReceiverActivity.class);
    18.         PendingIntent pendingIntent = PendingIntent.getActivity(this,
    19.             12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    20.         AlarmManager am =
    21.             (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
    22.         am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
    23.                 pendingIntent);
    24.     }
    25. }
    AlarmReceiverActivity - more than 20 errors..
    Code (Text):
    1. package com.example.worldcountriesbooks;
    2.  
    3.  
    4. public class AlarmReceiverActivity extends Activity {
    5.     private MediaPlayer mMediaPlayer;
    6.      
    7.     @Override
    8.     public void onCreate(Bundle savedInstanceState) {
    9.         super.onCreate(savedInstanceState);
    10.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    11.         this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    12.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
    13.         setContentView(R.layout.alarm);
    14.  
    15.         Button stopAlarm = (Button) findViewById(R.id.stopAlarm);
    16.         stopAlarm.setOnTouchListener(new OnTouchListener() {
    17.             public boolean onTouch(View arg0, MotionEvent arg1) {
    18.                 mMediaPlayer.stop();
    19.                 finish();
    20.                 return false;
    21.             }
    22.         });
    23.  
    24.         playSound(this, getAlarmUri());
    25.     }
    26.  
    27.     private void playSound(Context context, Uri alert) {
    28.         mMediaPlayer = new MediaPlayer();
    29.         try {
    30.             mMediaPlayer.setDataSource(context, alert);
    31.             final AudioManager audioManager = (AudioManager) context
    32.                     .getSystemService(Context.AUDIO_SERVICE);
    33.             if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
    34.                 mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
    35.                 mMediaPlayer.prepare();
    36.                 mMediaPlayer.start();
    37.             }
    38.         } catch (IOException e) {
    39.             System.out.println("OOPS");
    40.         }
    41.     }
    42.  
    43.         //Get an alarm sound. Try for an alarm. If none set, try notification,
    44.         //Otherwise, ringtone.
    45.     private Uri getAlarmUri() {
    46.         Uri alert = RingtoneManager
    47.                 .getDefaultUri(RingtoneManager.TYPE_ALARM);
    48.         if (alert == null) {
    49.             alert = RingtoneManager
    50.                     .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    51.             if (alert == null) {
    52.                 alert = RingtoneManager
    53.                         .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    54.             }
    55.         }
    56.         return alert;
    57.     }
    58. }
    main.xml - One error inr orw 9.
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent">
    6. <TextView
    7.     android:layout_width="fill_parent"
    8.     android:layout_height="wrap_content"
    9.     android:text="@string/hello"
    10.     android:id="@+id/test"
    11.     />
    12. </LinearLayout>
    alarm.xml - One exclamation error row 5.
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical" android:layout_width="fill_parent"
    4.     android:layout_height="fill_parent">
    5.     <Button android:text="Stop Alarm" android:id="@+id/stopAlarm"
    6.         android:layout_width="wrap_content" android:layout_height="wrap_content" />
    7. </LinearLayout>
    Do you need more information?
Loading...

Share This Page