Android闹钟不起作用

时间:2015-11-25 09:44:46

标签: android android-intent android-alarms

class扩展AsyncTask。它有3种方法predoInBackgroundpostExecute methods。所以我正在通过postExecute方法拨打电话。

@Override
public void onPostExecute(String result) {
    AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
    Intent intent = new Intent(context, OnAlarm.class);
    int time1 = 10000;

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.SECOND, time1);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,0);
    long x1=System.currentTimeMillis();
    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() , pendingIntent);
    Toast.makeText(context, "Alarm set",Toast.LENGTH_LONG).show();

    //super.onPostExecute(result);

    Log.v("erororrorororororo", result);
    Log.d("ttttttt", result);
    this.Prog1.setText(result + " pagaaal ");
    line = result;
    Log.v("god save me", line);
    if(result.equals("error")) {
        Log.v("erororrorororororo", line);
    } else {
        //Intent intent1 = new Intent(context, ListMenu.class);
        //context.startActivity(intent1);
    }
}

OnAlarm课程将接到报警电话。

package com.example.ishanvadwala.server;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.util.Log;

/**
 * Created by ruchit on 11/24/15.
 */
public class OnAlarm extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

       Log.v("BroadcastReceiver", "in onReceive:");
        MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.q);
        // Start the MainActivity
        mediaPlayer.start();
        Intent i = new Intent(context, Signup.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

// Android清单文件

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>

    <receiver  android:process=":remote" android:name="OnAlarm"></receiver>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <uses-permission android:name="android.permission.NFC" />
        <uses-permission android:name="android.permission.SEND_SMS" />
        <receiver  android:name="OnAlarm"></receiver>

        <uses-feature
            android:name="android.hardware.nfc"
            android:required="true" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.nfc.action.TAG_DISCOVERED" />
                <action android:name="android.nfc.action.TECH_DISCOVERED" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="text/plain" />
            </intent-filter>

            <meta-data
                android:name="android.nfc.action.TECH_DISCOVERED"
                android:resource="@xml/nfc_tech_list" />
        </activity>
        <activity android:name=".adapter" >

            <!-- Add an intent filter here if you wish -->
        </activity>
        <activity
            android:name=".login"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".Successful"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".ListMenu"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".loadingscreen"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".Signup"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".Floor7"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".AfterSignIn"
            android:label="@string/title_activity_after_sign_in"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

对不起家伙它的工作应该是PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,0);
而不是PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,0)