基本上我想在超出下面的类y
后发出警报声。
我有这个课程,我已将Context
作为参数传递:
public class Point {
private Context context;
private int x;
private int y;
public Point( Context context, int x, int y)
{
this.context=context;
this.x = x;
this.y = y;
if(y>30000){
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mp = MediaPlayer.create(context, notification);
mp.start();
}
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
我真的不知道如何在这个类中返回Context
,它有一个返回上面类中构造函数Point
的方法(它调用Point
类)但是这是我试过的:
public class UbidotsData {
public static Point getDataFromReceiver(int x)
{
ApiClient api = new ApiClient("A1E-0d8bec822d9d5ccae0fb08a75dfdb22e17c3");
Variable ldr = api.getVariable("5a5f80eec03f971388983b8e");
Value[] values = ldr.getValues();
int newValue = (int) values[0].getValue();
return new Point(Context.getContext,x, newValue); //error "cannot resolve symbol 'getContext'" occurs here
}
}
这是Context.java
类:
public class Context extends Application {
public static Context mcontext;
public void onCreate() {
super.onCreate();
mcontext= (Context) getApplicationContext();
}
public static Context getContext(){
return mcontext;
}
}
的AndroidManifest.xml:
<application
android:allowBackup="true"
android:name= "com.example.teerna.smartagriculturev5.Context"
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"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>