参考の記事
http://kuc-arc-f.com/agri/?blog=blog-2
========================================================
[ blog-1 ] でParse.com 活用した、
マイクロコンピュータからのセンサ値のクラウドへ保存、表示機能を開発しましたが。
http://kuc-arc-f.com/agri/?blog=blog-1
モバイル連携の機能を拡張し、
push通知を追加します。Androidのみ
code:
https://github.com/kuc-arc-f/android-agri-push
parse - Android - push 関係のページ(参考)
https://www.parse.com/docs/push_guide#top/Android
# サンプル-プロジェクトを参考に、Android Studioでビルドしていきます。
# keyの設定
https://github.com/kuc-arc-f/android-agri-push/blob/master/agripush/app/src/main/java/com/kuc_arc_f/agripush/Application.java
parse - setting -Keys 画面から 、key取得、設定。
pushされた時に、通知バーから起動される画面など設定。
Parse.initialize(this, "YOUR-APP-ID", "Your-Client-Key");
PushService.setDefaultPushCallback(this, PushAct.class);
# manifest ですが、pkgに依存されて、修正部分も多くなるので注意です。
この場合は、pkgname= com.kuc_arc_f.agripush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.kuc_arc_f.agripush" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<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.kuc_arc_f.agripush.permission.C2D_MESSAGE" | |
android:protectionLevel="signature" /> | |
<uses-permission android:name="com.kuc_arc_f.agripush.permission.C2D_MESSAGE" /> | |
<application | |
android:name="com.kuc_arc_f.agripush.Application" | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="com.kuc_arc_f.agripush.PushAct" | |
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" /> | |
<category android:name="com.kuc_arc_f.agripush" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
</manifest> |
ParseQuery.getQuery (parse - Android API) を使った、
クラウド側データ抽出後、adapter経由でリスト画面の表示処理。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void init_proc(){ | |
try | |
{ | |
final ParseQuery<ParseObject> query = ParseQuery.getQuery("SenObject1"); | |
query.orderByDescending("dtnum"); | |
query.setLimit( 1 ); | |
query.findInBackground(new FindCallback<ParseObject>() { | |
public void done(List<ParseObject> senList, ParseException e) { | |
if (e == null) { | |
ArrayList lst = new ArrayList<ItemSensor>(); | |
Log.d("score", "Retrieved : " + senList.size() + " scores"); | |
if(senList.size() > 0){ | |
ParseObject item = senList.get(0); | |
ItemSensor itm1= new ItemSensor(); | |
int iSnum1 = item.getInt("snum1"); | |
itm1.setSnum1( String.valueOf(iSnum1) ); | |
lst.add(itm1); | |
ItemSensor itm2= new ItemSensor(); | |
int iSnum2 = item.getInt("snum2"); | |
itm2.setSnum1( String.valueOf(iSnum2) ); | |
lst.add(itm2); | |
ItemSensor itm3= new ItemSensor(); | |
int iSnum3 = item.getInt("snum3"); | |
itm3.setSnum1( String.valueOf(iSnum3) ); | |
lst.add(itm3); | |
ItemSensor itm4= new ItemSensor(); | |
int iSnum4 = item.getInt("snum4"); | |
itm4.setSnum1( String.valueOf(iSnum4) ); | |
lst.add(itm4); | |
Long iDnum = item.getLong("dtnum"); | |
String s2 =String.valueOf(iSnum1)+ ":" + String.valueOf(iSnum2) + ":"+ String.valueOf(iSnum3) +":" + String.valueOf(iSnum4); | |
Log.d(TAG, "s=" + s2 + ":dt="+ String.valueOf(iDnum) ); | |
String sDate = get_dateString(String.valueOf(iDnum)); | |
try | |
{ | |
disp_proc(lst); | |
}catch(Exception ex){ | |
ex.printStackTrace(); | |
} | |
mLblText_01.setText( sDate ); | |
} | |
} else { | |
Log.d("score", "Error: " + e.getMessage()); | |
} | |
} | |
}); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} |
*) 開発者向けのまとめ記事
0 件のコメント:
コメントを投稿