I'm new on android development and I still don't understand Intent very well. Here i'm using Firebase to create notifications, I add an Intent to my notification, but when my app is in foreground and I click on the notification nothing happens (when the app is killed or in background it work well).
The strange thing is at a moment it was working, when I clicked on the notification the function "onNewIntent" of my "MainActivity" class was called, but now nothing happen anymore, and I think I changed nothing on the code.
Here is how I create my intent :
Notifications notifs = new Notifications(this);
String title = remoteMessage.getData().get("title");
String body = remoteMessage.getData().get("body");
String url = remoteMessage.getData().get("url");
Intent intentNotif = new Intent(this, MainActivity.class);
intentNotif.setAction(Intent.ACTION_MAIN);
intentNotif.addCategory(Intent.CATEGORY_LAUNCHER);
intentNotif.putExtra("url", url);
intentNotif.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
//intentNotif.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notifs.showNotif(title, body, true, intentNotif);
Here is how I add the intent to the notification :
this.builderGeneric.setContentIntent(PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT));
I also tried to create an intent with a custom action but it's not working, I tryed different intent flags, but I feel like i'm trying random things without knowing what I do, so that's why I'm asking for your help.
EDIT :
Here is how I create the notification if it's usefull :
Notifications(Context context) {
this.context = context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.notifManager = context.getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
channel.setDescription(CHANNEL_DESCRIPTION);
channel.enableLights(false);
channel.enableVibration(false);
channel.setSound(null, null);
if (this.notifManager != null) {
this.notifManager.createNotificationChannel(channel);
}
} else {
this.notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
this.builderGeneric = new Notification.Builder(context)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher_round);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.builderGeneric.setChannelId(this.CHANNEL_ID);
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
this.builderGeneric.setSmallIcon(R.mipmap.ic_launcher_foreground);
}
}
public void showNotif(String title, String text, boolean cancelable, Intent intent) {
this.builderGeneric.setContentTitle(title)
.setContentText(text)
.setOngoing(!cancelable)
.setContentIntent(PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT));
Notification notifGeneric = this.builderGeneric.build();
this.notifManager.notify(1, notifGeneric);
}
EDIT 2 : Here is my manifest :
<application
android:allowBackup="true"
android:fullBackupContent="#xml/backup_descriptor"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:launchMode="standard"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<receiver
android:name=".NetworkChangeReceiver"
android:label="NetworkChangeReceiver">
<intent-filter
android:name=".NetworkIntentFilter"
android:label="NetworkIntentFilter">
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE"
tools:ignore="BatteryLife" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
<service android:name=".MyFirebaseService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
OK, First try to remove
intentNotif.setAction(Intent.ACTION_MAIN);
intentNotif.addCategory(Intent.CATEGORY_LAUNCHER);
Next, adding android:launchMode="singleTask" (also removing android:launchMode="standard") inside your activity tag in AndroidManifest.xml.
Then try again, please aware that with the launchMode is singleTask and if you click on your notification while your MainActivity is opened -> onNewIntent will be triggered (because Android will not create one more instance of this Activity) otherwise onCreate will be called.
And if it works, I would like to recommend you to read more about LaundMode here
Related
When I click on Notification I should be navigated to Main2Activity and when I click on back button of Main2Activity I should be navigated back to MainActivitybut I am getting navigated back to Home screen.
Is there any mistake in my code?
NotificationCompat.Builder noti = new NotificationCompat.Builder(MainActivity.this);
noti.setContentTitle("Message for you!");
noti.setContentText("Hi!!This is message for you");
noti.setSmallIcon(R.drawable.ic_launcher_background);
noti.setTicker("app name:message app");
noti.setAutoCancel(true);
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
TaskStackBuilder taskStackBuilder=TaskStackBuilder.create(MainActivity.this);
taskStackBuilder.addParentStack(MainActivity.class);
taskStackBuilder.addNextIntent(intent);
PendingIntent pendingIntent=
taskStackBuilder.getPendingIntent(1234,PendingIntent.FLAG_UPDATE_CURRENT);
noti.setContentIntent(pendingIntent);
Notification notification=noti.build();
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1234,notification);
Mainifest.XML file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sainathpawar.notifications">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="second_filter" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Please try this
<activity
android:name=".Main2Activity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
It is because you are not within a stack. You only launched one activity. Your default MainActivity has not been created or launched.
You can handle the back button press with android.R.id.home in the OnMenuItemSelected callback and redirect them wherever you would like. You can try the "parent activity" route as well, but I'm not certain how that works when launched from notification without context of the parent to launch it to begin with.
If you go that route, update to let us know if it worked for you.
Otherwise you can easily use my answer as well.
EDITED FOR CLARITY
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
startActivity(Main2Activity.this, MainActivity.class);
return true;
finish();
}
return super.onOptionsItemSelected(item);
}
taskStackBuilder.getPendingIntent(1234,PendingIntent.FLAG_UPDATE_CURRENT);
noti.setContentIntent(pendingIntent);
There was error in coding at above line.If we see here the requestcode is 1234 which is same as ID of notify method
notificationManager.notify(1234,notification);
so it was navigating back to Home screen because Android OS was thinking as if its on MainActivity because of 1234 request code in getPendingIntent.
****Solution is:****change requestCode of getPendingIntent() method from 1234 to any random number I changed it to 0 and it worked for me.
You can achieve this by PendingIntent without TaskStackBuilder as:
Intent parentIntent = new Intent(this, MainActivity.class);
parentIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Intent resultIntent = new Intent(this, Main2Activity.class);
final PendingIntent pendingIntent = PendingIntent.getActivities(context, 0,
new Intent[] {parentIntent, resultIntent}, PendingIntent.FLAG_UPDATE_CURRENT);
noti.setContentIntent(pendingIntent);
I want to be able to start a BroadcastReceiver when a Google Fit session starts or ends on a phone. I have the manifest set up for the receivers:
<receiver android:name=".YogaSessionStartedBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.session_start" />
<data android:mimeType="vnd.google.fitness.activity_type/yoga" />
</intent-filter>
</receiver>
<receiver android:name=".YogaSessionEndedBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.session_end" />
<data android:mimeType="vnd.google.fitness.activity_type/yoga" />
</intent-filter>
</receiver>
And I'm starting a session with activity type YOGA in my app:
mSession = new Session.Builder()
.setName(SESSION_NAME)
.setIdentifier(getString(R.string.app_name) + " " + System.currentTimeMillis())
.setDescription("Yoga Session Description")
.setStartTime(Calendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS)
.setActivity(FitnessActivities.YOGA)
.build();
PendingResult<Status> pendingResult =
Fitness.SessionsApi.startSession(mGoogleApiClient, mSession);
However onReceive is never called in my BroadcastReceivers. Any suggestions?
Have you Register for Session ?
registerForSessions (GoogleApiClient client, PendingIntent intent)
Something like this:
Intent intent = new Intent(mContext,YogaSessionEndedBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0);
Fitness.SessionsApi.registerForSessions(mClient,pendingIntent);
Which mClient is your GoogleApiClient,And mContext is your Activity Context.
I am implement GCM Push Notification in my app and its successfully done but in some devices it not show notification when app is close.
List of device which notication is not show:
Redmi-2
lenovo
Gionee
Can anyone explain me what is problem and how i solve its.
here my manifest:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.Controller"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".ListOfClass"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".EditProfile"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".ShowStudentList"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<receiver
android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="schoolstar.com.catalyst.android.skoolstar" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
<activity
android:name=".Message"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".Attendance"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".NewMessage"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".GroupMessage"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".Test_Chat"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
</application>
</manifest>
here my service name GCMNotificationIntentService:-
public class GCMNotificationIntentService extends GCMBaseIntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Database db;
private Controller aController = null;
public GCMNotificationIntentService() {
// Call extended class Constructor GCMBaseIntentService
super(Constants.GOOGLE_SENDER_ID);
}
public static final String TAG = "GCMNotificationIntentService";
#Override
protected void onRegistered(Context context, String registrationId) {
}
#Override
protected void onUnregistered(Context context, String registrationId) {
Log.d("unref",registrationId);
if(aController == null)
aController = (Controller) getApplicationContext();
Toast.makeText(getApplicationContext(),"hello no",Toast.LENGTH_LONG).show();
aController.displayMessageOnScreen(context,
getString(R.string.gcm_unregistered));
aController.unregister(context, registrationId);
}
#Override
public void onError(Context context, String errorId) {
Log.d("error","");
if(aController == null)
aController = (Controller) getApplicationContext();
aController.displayMessageOnScreen(context,
getString(R.string.gcm_error, errorId));
}
#Override
protected void onMessage(Context context, Intent intent) {
if(aController == null)
aController = (Controller) getApplicationContext();
aController.acquireWakeLock(getApplicationContext());
String message = intent.getExtras().getString("message");
String formuser = intent.getExtras().getString("formuser");
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+5:30"));
Date currentLocalTime = cal.getTime();
DateFormat date = new SimpleDateFormat("HH:mm a");
date.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
String localTime = date.format(currentLocalTime);
db = new Database(context);
int from_id = 0;
List<FetchData> fetchdata = db.getAllContacts();
for (FetchData fd : fetchdata)
{
from_id=fd.getID();//get ser no
}
db.storeMessage(420, formuser, from_id + "", message, "text", localTime, "F", "ST", "R");
aController.displayMessageOnScreen(context, message);
// notifies user
sendNotification(context,message);
}
private void sendNotification(Context context,String msg) {
String app_name = context.getResources().getString(R.string.app_name);
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, ListOfClass.class), 0);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(app_name)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText("New Message")
.setSound(alarmSound);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
// Log.d(TAG, "Notification sent successfully.");
}
}
When I am see the whatsapp, hike and others notification app he will always run in background thread but my app is not running always in background. So may be this reason be also.
I am recently working on android please help me.Thanks in advance!
I faced similar issue with Redmi-2. There is no problem in the code but it is due to Custom UI provided by the Manufacturer like MIUI 6.
So to enable GCM notifications
Go to Security App >> Tap on permissions >> Tap on Auto Start and enable auto start for your App.
There are two major reasons for that
1 - Some devices does not allow you to run a service on background like redmi-2 ( almost on all xiaomi device ). Even whats app could not work properly on them unless user allow them by going to Security App >> Tap on permissions >> Tap on Auto Start and enable auto start for whatsapp etc. In this case all you can do is to show the details of this to user on application start up. And open that screen and guide user ( if possible ) like clean master.
2- Second reason is that it didn't work on one of those phone whose Google Play Services app wasn't installed correctly(and its essential for GCM). You can not do anything on these devices also. The only thing you can do in this case is just show some message to user about this.
So from my experience there always be a number of users(but very small percentage) who wont receive GCM push.
There is concept of whitelisting in Xiaomi's phone. So, if you put log in onReceive of gcm, you will notice that gcm is receiving but it's not processing further. Its cause your app is not whitelisted.
Xiaomi for security purposes disables the Notification for each Application. Follow these steps to receive messages in background once they quit the app using cleaner.
Enable Autostart
Enable Floating and Lock Screen Notification
Enable AutoStart
Open Security App.
Got to Permissions, then Click on Auto Start Management.
Add/Enable auto start apps (e.g. Whatsapp).
Enable Floating and Lock Screen Notification
Open Settings App.
Click on Notifications, then click on Manage Notifications.
Tap on the App which you are looking for (e.g. WhatsApp).
Enable Show in notification shade / Show on lockscreen and in drop down option.
For Reference check this out : http://support.hike.in/entries/55998480-I-m-not-getting-notification-on-my-Xiaomi-Phone-For-MIUI-6-
i got success with this.. Hope it helps..
Facing the same issue, the only things we did are to educate xiaomi users to do the steps as #anup-dasari mentioned, and set the gcm priority to high, with possibility to have persistent service in the future
I'm using Notifications in Android. When the user clicks them, I have to open the application and redirect him to one specific Activity, it works fine if the user who gets the notifications didn't have the application opened. (I mean, opened in background), if he has the application opened, when he clicks the notification he is redirected to the "Main" activity when I want to redirect him to the same activity.
I guess that it could be some mistake in my AndroidManifest.xml,, but, I'm not sure, could you someone help me??
My manifest:
<application
android:screenOrientation="portrait"
android:debuggable="true"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<!-- android:theme="#style/AppTheme" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" -->
<activity
android:name="com.trivialword.activities.MainDisplayActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.trivialword.activities.ResultActivity"
android:label="#string/title_activity_result"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen" >
</activity>
And here is where I configure the notification
Context contexto = context.getApplicationContext();
CharSequence title = "Trivial Invitación";
CharSequence description = "Invitacion a una partida del usuario " + msg;
Intent notIntent = new Intent(contexto,
GameOnePlayerPrivateOnlineActivity.class);
notIntent.putExtra("opponent", true);
notIntent.putExtra("who-create-game", msg);
PendingIntent contIntent = PendingIntent.getActivity(
contexto, 0, notIntent, 0);
notif.setLatestEventInfo(
contexto, title, description, contIntent);
Thank you!.
In intent declaration, try to write this.
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Creating a simple notification:
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
I think, that is the problem.
Okay, so, I'll preface this by stating I'm using Titanium, so that'll, I assume, put a bad taste in your mouth. So, I'm sorry for my lack on knowledge on the Android side of things.
So, I've got a thing set up to receive GCM notifications. I can send them correctly to my app, and the code runs and tries to launch my app when it's clicked. However, it's just giving me this in the 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: com.android.internal.view.IInputMethodClient$Stub$Proxy#427a60a8 attribute=null
I got the C2DM receiving stuff from a third party, and I've tried to modify it to do what I need, but I'm clearly doing something not quite right.
Here's the 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);
}
Here's my manifest stuff (I think)
<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>
There's also another manifest section in a different place, because of how Titanium handles things:
<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>
If the app is already open, it runs some Titanium code, which I think I'll be able to figure out, but if the app is not open, it hits stuff in the onMessage which I can't quite figure out.
Any help would be appreciated. Thanks.
This line:
Intent launcherintent = new Intent("com.geneca.journaling.mobile.GenecaJournalingActivity");
Creates a new Intent with the action com.geneca.journaling.mobile.GenecaJournalingActivity.
Is this what you wanted?
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);
or
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);