![](/img/trans.png)
[英]Android Push Notifications on Android Device that can not install Google Play Services
[英]Activity of Device is not detecting in Android using Google Play Services
我嘗試使用Google Play服務庫獲取設備活動,例如設備正在車輛,自行車,步行或跑步中旅行或不旅行,但ActivityRecognitionResultResult為null。
嘗試的代碼在Class1.java中:
public class Class1 extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
public static String ACTION_STRING= "action";
Intent intentp = new Intent(context, Class2.class);
intentp.setAction(ACTION_STRING);
pendingIntent = PendingIntent.getBroadcast(context, 0, intentp, PendingIntent.FLAG_ONE_SHOT);
}
}
以及Class2.java中的代碼:-
public class Class2 extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
if(intent.getAction() == Alarm.ACTION_STRING)
{
if(ActivityRecognitionResult.hasResult(intent)) //Here condition getting as false
{
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity detectedActivity = result.getMostProbableActivity();
int activityType = detectedActivity.getType();
if(activityType != DetectedActivity.STILL)
{
//Here doing something;
}
}
}
}
}
如何使用Google Play服務檢測設備的活動?
從文檔中 :
使用ActivityRecognitionClient需要com.google.android.gms.permission.ACTIVITY_RECOGNITION權限。
是您的應用正確請求的權限嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.