Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 报警管理器和通知不工作_Java_Android_Alarmmanager - Fatal编程技术网

Java 报警管理器和通知不工作

Java 报警管理器和通知不工作,java,android,alarmmanager,Java,Android,Alarmmanager,我尝试了一种在特定时间显示通知的方法,但仍然没有效果。用于将一个类用于alarmmanager,一个类用于通知,然后将通知添加到清单中 public class MainActivity extends Activity { private WebView wv1; Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onC

我尝试了一种在特定时间显示通知的方法,但仍然没有效果。用于将一个类用于alarmmanager,一个类用于通知,然后将通知添加到清单中

public class MainActivity extends Activity {

    private WebView wv1;
    Context context;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wv1 = (WebView) findViewById(R.id.YahooWhether);
        final TextView time = (TextView) findViewById(R.id.hello1);

        wv1.getSettings().setLoadsImagesAutomatically(true);
        wv1.getSettings().setJavaScriptEnabled(true);
        wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        wv1.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(MainActivity.this, "here u go", Toast.LENGTH_SHORT).show();
            }
        });
        wv1.loadUrl("https://www.yahoo.com/news/weather/pakistan/sindh/karachi-2211096/");

        Intent myIntent = new Intent(MainActivity.this , notify.class);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(TimeZone.getTimeZone("Pakistan"));
        calendar.set(Calendar.HOUR_OF_DAY, 17);
        calendar.set(Calendar.MINUTE, 20);
        calendar.set(Calendar.SECOND, 00);

        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY , pendingIntent);

    }
}
这是通知类

public class notify extends BroadcastReceiver{
    Context context;
    @Override
    public void onReceive(Context context, Intent intent) {

        Notification.Builder mBuilder =
                new Notification.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher_round)
                        .setContentTitle("Whether Update")
                        .setContentText("Tomorrow's Forecast");

        // Gets an instance of the NotificationManager service
        NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(001, mBuilder.build());
    }
}
最后这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.inara.whetherapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android:name=".notify"
            android:enabled="true"
            android:exported="true"></receiver>

    </application>
<uses-permission android:name="android.permission.INTERNET" />


pendingent.getService()
用于启动
服务。您正试图将广播发送到
广播接收器
。使用
pendingent.getBroadcast()
代替.mNotificationManager.notify(001,mBuilder.build());001不是一个有效的整数,请传递有效的整数,如1,2,然后再试一次。那么设置时区正确吗?实际上,没有警报管理器的通知没有问题,它在应用程序启动时正确显示,但现在我想每天在特定时间显示它。我认为巴基斯坦的时区是亚洲/卡拉奇,或者你可以用谷歌搜索它。