从启动库项目的Andr​​oid应用程序 [英] Launch Android application from Library project

查看:235
本文介绍了从启动库项目的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发在Android电子图书馆android应用的PushNotification。我无法同时单击推送通知消息,推出的Andr​​oid应用程序。 我无法获取库项目中的Andr​​oid应用程序类中推出generatePushNotification()方法。以下是从库项目的code片段。

I am developing the PushNotification for android application in Android Library. I am unable to launch the android application while clicking the push notification message. I am unable to fetch the android application class in library project for launch in generatePushNotification() method. The following is the code snippet from 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);      

}

如何启动图书馆计划的android应用?

How can I launch the android application from the Library Project.?

推荐答案

如果你的问题是,你希望提供给意图的活动库项目无法识别,则可以使用 packageManager.getLaunchIntentForPackage()获得意图从这个包具有的 CATEGORY_LAUNCHER 属性

if your problem is that the activity you wish to provide to the intent is not recognized in the library project, you can use the packageManager.getLaunchIntentForPackage() to get intent to start activity from this package which have CATEGORY_LAUNCHER attribute

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

,那么你可以替换新意图(背景下,需要推出的Andr​​oid应用程序的主活动) launchIntent

这篇关于从启动库项目的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆