I am sending push notifications from pasrse.com, I want to save push notifications so that they can be seen later after closing the application.
I can receive notifications in a separate text form, but if I switch to another activity, notifications will disappear.
MainActivity.java
public class MainActivity extends ActionBarActivity {
Button Notify;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Notify = (Button)findViewById(R.id.notify);
Notify.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DisplayPush.class);
intent.putExtra("com.parse.Data","String text");
startActivity(intent);
}
});
}
DisplayPush.java
public class DisplayPush extends Activity {
String jsonData;
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String Titletobeput = "title";
public static final String Messagetobeput = "mess";
SharedPreferences sharedpreferences;
@Override
public void onBackPressed(){
Intent myIntent = new Intent(DisplayPush.this,MainActivity.class);
startActivity(myIntent);
finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification);
TextView notification_title = (TextView) findViewById(R.id.title);
TextView notification_message = (TextView) findViewById(R.id.message);
ParseAnalytics.trackAppOpened(getIntent());
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if(extras !=null)
if(extras.containsKey("com.parse.Data"))
jsonData = extras.getString("com.parse.Data");
String jsonData = extras.getString("com.parse.Data");
try{
JSONObject notification = new JSONObject(jsonData);
String Title = notification.getString("title");
String Message = notification.getString("alert");
notification_message.setText(Message);
notification_title.setText(Title);
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Titletobeput, Title);
editor.putString(Messagetobeput, Message);
editor.commit();
}
catch(JSONException e){
Toast.makeText(getApplicationContext(), "Something went wrong with the notification", Toast.LENGTH_SHORT).show();
}
}
}
Notification.xml (notifications are shown)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp" />
<TextView
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="22dp"
android:layout_marginTop="80dp" />
</RelativeLayout>
ActivityMain.xml (just a button to display the notification button)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="hasan.parsereceiveandshow.MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Press the button to display notifications" />
<Button
android:id="@+id/notify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="44dp"
android:layout_marginTop="63dp"
android:text="See Notifications" />
</RelativeLayout>
Is there a way by which I can automatically display a full notification in the status / notification dialog box? Because long messages are truncated.
user4323984
source
share