1

这是一个两部分的问题。我的应用程序可以使用推送通知,但无法使用自定义声音,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);    
    }
4

0 回答 0