如果在拥有Uri到该资源时确实存在android.resource://

时间:2016-03-01 18:58:41

标签: android android-studio push-notification android-resources

我正在使用Android studio进行推送通知,我的手机通过USB插入作为调试设备,通知只需很好的自定义文本设置等。但是当我尝试使用

Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.alarm);

然后评估为android.resource://gcm.play.android.samples.com.gcmquickstart/2131099648它不会打球。

我的猜测是声音文件不存在,它只是无声地失败。

代码:

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.alarm);
    // RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(message)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

我如何调试应用程序,通过使用Url我可以确认资源是否存在?

0 个答案:

没有答案