如何在我们的应用程序中安排消息到 WhatsApp?
How to schedule a message in our application to WhatsApp?
我想通过我的应用程序在 WhatsApp 中发送、安排短信。可以吗?
目前,我可以使用此代码打开 WhatsApp
Intent i=getpackageManager().getLaunchIntentForPackage("com.whatsapp");
startActivity(i);
但是,是否可以安排从我们的应用程序向 WhatsApp 发送消息?
But i would like to know how to schedule message from our application to what'sapp
没有,目前没有API
您可以使用 AlarmManager
来安排未来的任何任务..
在您的 Activity/Fragment
中使用这行代码来安排任何任务:-
Intent myIntent = new Intent(AlaramClass.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(AlaramClass.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, "SPECIFY_YOUR_TIME_HERE_TO_SCHEDULE_TASK", pendingIntent);
然后创建接收器来接收未来的任务
public class AlarmReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Intent i=getpackageManager().getLaunchIntentForPackage("com.whatsapp");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
并且不要忘记 Manifest 中的 Receiver 条目(在 <application>.....</应用>)
<receiver
android:name=".AlarmReceiver"
android:exported="true" >
</receiver>
并且您需要为其添加 WAKE_LOCK 权限,如下所示:-
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
我想通过我的应用程序在 WhatsApp 中发送、安排短信。可以吗?
目前,我可以使用此代码打开 WhatsApp
Intent i=getpackageManager().getLaunchIntentForPackage("com.whatsapp");
startActivity(i);
但是,是否可以安排从我们的应用程序向 WhatsApp 发送消息?
But i would like to know how to schedule message from our application to what'sapp
没有,目前没有API
您可以使用 AlarmManager
来安排未来的任何任务..
在您的 Activity/Fragment
中使用这行代码来安排任何任务:-
Intent myIntent = new Intent(AlaramClass.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(AlaramClass.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, "SPECIFY_YOUR_TIME_HERE_TO_SCHEDULE_TASK", pendingIntent);
然后创建接收器来接收未来的任务
public class AlarmReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Intent i=getpackageManager().getLaunchIntentForPackage("com.whatsapp");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
并且不要忘记 Manifest 中的 Receiver 条目(在 <application>.....</应用>)
<receiver
android:name=".AlarmReceiver"
android:exported="true" >
</receiver>
并且您需要为其添加 WAKE_LOCK 权限,如下所示:-
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>