//Application
package com.tutorial.Alert;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseInstallation;
import com.parse.ParseObject;
import com.parse.ParseUser;
public class SampleApplication extends Application {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
ParseObject.registerSubclass(Alert.class);
Parse.initialize(this, "ABC", "XYZ");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
}
}
//Subclass
package com.tutorial.Alert;
import com.parse.ParseClassName;
import com.parse.ParseObject;
import com.parse.ParseQuery;
@ParseClassName("Alert")
public class Alert extends ParseObject {
{
return getString("title");
}
{
return getString("category");
}
public String getDescription
() {
return getString("description");
}
public static ParseQuery<Alert> getQuery() {
return ParseQuery.getQuery(Alert.class);
}
}
//MainActivity where you retrieve data
package com.tutorial.Alert;
import java.util.List;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import com.parse.CountCallback;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
public class MainActivity extends ActionBarActivity {
public static final String TAG
= "AlertMainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
ConnectivityManager cm
= (ConnectivityManager
) getSystemService
(Context.
CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo();
if ((ni != null) && (ni.isConnected())) {
ParseQuery<Alert> query = Alert.getQuery();
query.whereEqualTo("category", "Serious");
Log.d(TAG,"before calling query");
query.findInBackground(new FindCallback<Alert>() {
{
if(exp == null){
for(int i=0;i<list.size();i++)
{
Alert alert = list.get(i);
Log.d(TAG, "Title = "+ alert.getTitle() + " desc = "+ alert.getDescription());
}
} else {
Log.d(TAG,"no results !!"+ exp.getMessage()+" code ="+ exp.getCode());
}
};
});
} else{
if(null == ni)
Log.d(TAG, "ni is null");
if(!ni.isConnected())
Log.d(TAG,"network is not connected");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://s...content-available-to-author-only...d.com/apk/res/android"
package="com.tutorial.Alert"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.tutorial.Alert.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.tutorial.Alert.permission.C2D_MESSAGE" />
<application
android:name="com.tutorial.Alert.SampleApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: If you change the package name of this sample app,
change "com.parse.tutorials.pushnotifications" in the lines
below to match the new package name.
-->
<category android:name="com.tutorial.Alert" />
</intent-filter>
</receiver>
</application>
</manifest>