【发布时间】:2015-12-14 15:53:40
【问题描述】:
我想做的事:
- 我正在尝试向所有正在使用的联系人发送消息 whatsapp 使用我的联系人列表中的服务
- 有可能吗?
- 如果可能怎么做?
我能做什么:我可以启动whats应用程序,我可以向它传递一条短信,然后通过我创建的单个联系人或组发送消息
下载服务.java
public class DownloadService extends Service {
public static boolean serviceState = false;
@Override
public void onCreate() {
serviceState = true;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("SERVICE-ONCOMMAND", "onStartCommand");
return START_STICKY;
}
@Override
public void onDestroy() {
Log.d("SERVICE-DESTROY", "DESTORY");
serviceState = false;
//Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();
}
@Override
public IBinder onBind(Intent intent) {
// We don't provide binding, so return null
return null;
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samples.customprogressloader" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".DownloadService"
android:enabled="true" />
</application>
</manifest>
在OnCreate 活动方法中,我正在启动服务,
startService(new Intent(this, DownloadService.class));
I am using this method to send message through whats app from here docs
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
【问题讨论】:
标签: android