1
好吧,我會在前言中說明我正在使用鈦,所以我認爲這會讓您的口腔不好。所以,我很抱歉我在Android方面的知識缺乏。從我的通知接收器啓動另一項活動
所以,我已經設置了一個接收GCM通知的東西。我可以將它們正確地發送到我的應用程序,並且代碼運行並嘗試在單擊它時啓動我的應用程序。然而,它只是給我這個在logcat中:
I/ActivityManager( 307): START {act=com.geneca.journaling.mobile.GenecaJournalingActivity cat=[android.intent.category.LAUNCHER] flg=0x34000000 bnds=[0,102][720,230] u=0} from pid -1
W/InputMethodManagerService( 307): Window already focused, ignoring focus gain of: [email protected] attribute=null
我得到了C2DM從第三方接收的東西,我一直試圖修改它做什麼,我需要,但我清楚地做一些事情不完全正確。
這裏是在onMessage:
@Override
protected void onMessage(Context context, Intent intent) {
Log.d(LCAT, "Message received");
HashMap data = new HashMap();
for (String key : intent.getExtras().keySet()) {
Log.d(LCAT, "Message key: " + key + " value: "
+ intent.getExtras().getString(key));
String eventKey = key.startsWith("data.") ? key.substring(5) : key;
data.put(eventKey, intent.getExtras().getString(key));
}
if (C2dmModule.getInstance() == null) {
int icon = 0x7f020000; // get this from R.java
CharSequence tickerText = "Geneca Journaling";
long when = System.currentTimeMillis();
Bundle extras = intent.getExtras();
CharSequence contentTitle = "Rate your journal";
CharSequence contentText = "Notification Content";
String title = extras.getString("title");
String message = extras.getString("message");
if(title != null) {
contentTitle = title;
}
if (message != null) {
contentText = message;
}
//Intent notificationIntent = new Intent(this, C2DMReceiver.class);
Intent launcherintent = new Intent("com.geneca.journaling.mobile.GenecaJournalingActivity");
launcherintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
launcherintent
.setComponent(ComponentName
.unflattenFromString("com.geneca.journaling.mobile.GenecaJournalingActivity"));
launcherintent.addCategory("android.intent.category.LAUNCHER");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
launcherintent, 0);
// the next two lines initialize the Notification, using the
// configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.defaults = Notification.DEFAULT_ALL;
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(1, notification);
} else
C2dmModule.getInstance().sendMessage(data);
}
這裏是我的清單的東西(我認爲)
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<activity android:name=".GenecaJournalingActivity"/>
<permission
android:name="com.geneca.journaling.mobile.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.geneca.journaling.mobile.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application>
<service android:name="com.findlaw.c2dm.C2DMReceiver"/>
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.geneca.journaling.mobile"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.geneca.journaling.mobile"/>
</intent-filter>
</receiver>
</application>
</manifest>
</android>
也有在不同的地方另一個明顯的部分,因爲鈦是如何處理的事情:
<android:manifest>
<permission android:name="com.geneca.journaling.mobile.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.geneca.journaling.mobile.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Send the registration id to the server -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- App must have this permission to use the library -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<activity android:name="com.geneca.journaling.mobile.GenecaJournalingActivity"/>
<application>
<!-- In order to use the c2dm library, an
application must declare a class with the name C2DMReceiver, in its
own package, extending com.google.android.c2dm.C2DMBaseReceiver
It must also include this section in the manifest, replacing
"com.google.android.apps.chrometophone" with its package name.
-->
<service android:name="com.findlaw.c2dm.C2DMReceiver" />
<!-- Only google service can send data messages for the app. If permission is not set -
any other app can generate it -->
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Start receiver on boot -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.geneca.journaling.mobile" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.geneca.journaling.mobile" />
</intent-filter>
</receiver>
</application>
</android:manifest>
如果應用程序已經打開,它會運行一些Titanium代碼,我認爲我將能夠弄清楚,但是如果應用程序沒有打開,它會在onMessage中找到我無法弄清楚的東西。
任何幫助,將不勝感激。謝謝。
這不是在同一個應用程序,我想。 Titanium負責管理創建Java併爲我的主應用程序編譯它,但是我正在編譯獨立於此的C2DM接收器,因此GenecaJournalingActivity甚至不存在於該上下文中。 (在旁註中,我已經決定將來我不打算使用Titanium ...) – 2012-07-09 21:00:27
已更新的代碼。無論如何,我的意思是你的行爲是不正確的。 – Ran 2012-07-09 21:04:36
好吧,讓我這個錯誤:'msg:android.content.ActivityNotFoundException:無法找到明確的活動類{com.geneca.journaling.mobile/com.geneca.journaling.mobile.MainActivity};' – 2012-07-09 21:39:02