Android实现微信自动抢红包的程序

2019-12-10 19:08:07王旭

activity_main.xml

<RelativeLayout xmlns:android="http://www.easck.com/apk/res/android" 
xmlns:tools="http://www.easck.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity"> 
<Button 
android:id="@+id/start" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="10dp" 
android:layout_centerInParent="true" 
android:textSize="18sp" 
android:text="打开辅助服务"/> 
</RelativeLayout> 

MainActivity.java

package com.jackie.webchatenvelope; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 
public class MainActivity extends Activity { 
private Button startBtn; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
startBtn = (Button) findViewById(R.id.start); 
startBtn.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
try { 
//打开系统设置中辅助功能 
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 
startActivity(intent); 
Toast.makeText(MainActivity.this, "找到抢红包,然后开启服务即可", Toast.LENGTH_LONG).show(); 
} catch (Exception e) { 
e.printStackTrace(); 
} 
} 
}); 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
// Inflate the menu; this adds items to the action bar if it is present. 
getMenuInflater().inflate(R.menu.menu_main, menu); 
return true; 
} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
// Handle action bar item clicks here. The action bar will 
// automatically handle clicks on the Home/Up button, so long 
// as you specify a parent activity in AndroidManifest.xml. 
int id = item.getItemId(); 
//noinspection SimplifiableIfStatement 
if (id == R.id.action_settings) { 
return true; 
} 
return super.onOptionsItemSelected(item); 
} 
}