Android - 推送通知声音和打开活动问题

时间:2013-04-14 13:17:10

标签: android push-notification google-cloud-messaging

这是一个两部分问题。我的推送通知适用于我的应用程序,但我无法获得自定义声音,1。2.当您从通知栏中单击时,我无法收到打开应用程序的通知。

这是下面的代码。我尝试过各种导入自定义声音的东西。我的资产/声音文件夹中的声音。这将在安装时与apk一起进行,以及如何访问它?我正在使用webview以及将应用程序打开到通知中的特定链接,是否也可以这样做?

private void sendGCMIntent(final Context theContext, String theMessage) 
    {   
    int icon = R.drawable.noti_icon;
        long when = System.currentTimeMillis();

        NotificationManager notificationManager = (NotificationManager)
                theContext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, theMessage, when);

        String title = theContext.getString(R.string.app_name);

        Intent notificationIntent = new Intent();
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(theContext, 0, notificationIntent, 0);
        notification.setLatestEventInfo(theContext, title, theMessage, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        //String path = "file:///android_asset/sounds/soft.mp3"; 

        //File file = new File(path);

        //Log.i(TAG,"Sound exists : " + file.exists());
        Uri soundUri = Uri.parse("file:///android_asset/sounds/soft.mp3");

        if (soundUri != null) {
            notification.sound = soundUri;
        }
        else {
            notification.defaults |= Notification.DEFAULT_SOUND;
        }
        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);    
    }

0 个答案:

没有答案