Launch Android application from library project

I am developing a PushNotification application for Android in the Android library. I can not start the Android application by clicking on the push push message. I cannot extract the Android application class into the library project to run in the generatePushNotification () method. The following is a snippet of code from a library project.

private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); // Here I am getting the android application context as sActiveContext Intent notificationIntent = new Intent(context, "need to launch the android application main activity"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification); } 

How to launch an Android application from a library project?

+2
android android-intent push-notification android-library
source share
1 answer

if your problem is that the activity that you want to ensure the intent is not recognized in the library project, you can use packageManager.getLaunchIntentForPackage () to get the intent to start working with this package with the CATEGORY_LAUNCHER attribute

 String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); 

then you can replace new Intent(context, "need to launch the android application main activity") with launchIntent

+3
source share

All Articles