안드로이드를 처음 사용했습니다. 장치에서 배경 화면이 변경되면 알림 표시 줄에 메시지를 보내는 브로드 캐스트 수신기를 사용하는 응용 프로그램을 만들려고합니다. 기기에 성공적으로 설치되었지만 예상대로 작동하지 않습니다. 여기에 코드브로드 캐스트 수신기
WallPagerNotificationReceiver.java
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
public class WallPaperNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
this.sendNotification(context, "You have changed Wallpaper");
}
private void sendNotification(Context ctx, String message)
{
//Get the notification manager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nm =
(NotificationManager)ctx.getSystemService(ns);
//Create Notification Object
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification =
new Notification(icon, tickerText, when);
//Set ContentView using setLatestEvenInfo
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, 0);
notification.setLatestEventInfo(ctx, "Intimation", message, pi);
//Send notification
nm.notify(1, notification);
Toast.makeText(ctx,"Hello Nawin",Toast.LENGTH_LONG).show();
}
}
Manifest.xlm
<xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.ac.srmuniv"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".WallPaperNotificationReceiver">
<intent-filter>
<action android:name="android.intent.action.WALLPAPER_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
은 방송 수신기를 사용하려면이 올바른 방법은 무엇입니까? 그렇다면 내가 실수 한 부분을 도와 주시겠습니까?
미리 감사드립니다.
P .: 활동 또는 서비스를 사용하지 않습니다.
<receiver android:name=".WallPaperNotificationReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_WALLPAPER_CHANGED" />
</intent-filter>
</receiver>
이 실제 방송입니다 :
http://developer.android.com/reference/android/content/Intent.html#ACTION_WALLPAPER_CHANGED
질문이 명확하지 않습니다. 예상되는 행동은 무엇이며 대신 무엇을보고 있습니까? – Kuffs
내 예상 결과는 내가 배경 화면을 변경할 때 알림 메시지를 얻는 것입니다. 내 문제는 지금 나는 어떤 알림도 내가 벽지를 변경하지 않고있어. – Vijay
나는 수신기에 대한 수정을 넣어. 그러나 알림 코드는 테스트하지 않았습니다. onReceive 메소드에서 토스트를 사용하여 방송을 수신했는지 확인하는 것이 가장 좋습니다. –