How to make an activity to open a url - Android Studio

Hello! I dont know much about coding so i decided to buy an app about quotes. The thing is i have opened it in android studio and want to make some changes. Specifically i want i want to change the button ''authors'' and instead of opening an activity i want to open a web link. How i am supposed to do that?
I hope this bit of code helps :
I think the button i want to change is this in the android manifest
<activity
android:name="com.axdev.quotes.AuteursActivity"
android:label="@string/title_activity_auteurs"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- Points to searchable activity -->
<meta-data android:name="android.app.default_searchable"
android:value=".AuteursActivity" />
<!-- Points to searchable meta data -->
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>

Hi!
Code:
author_button.setOnClickListener(buttonClick);
private View.OnClickListener buttonClick = new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("your link"));
startActivity(intent);
}
};

Where to put code
Ducktamine said:
Hi!
Code:
author_button.setOnClickListener(buttonClick);
private View.OnClickListener buttonClick = new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("your link"));
startActivity(intent);
}
};
Click to expand...
Click to collapse
Thank you very much for your reply! Where do i have to put this code? In the android manifest? Also do i have to replace something first?

Looks like it should be in com.axdev.quotes.AuteursActivity, just find the place where click listener for button ''authors'' is setted. And replace code of listener.

Button
I cant find it. Here is th code
public class AuteursActivity extends ActionBarActivity {
private ArrayList<Quote> imageArry = new ArrayList<Quote>();
private AuthorsListAdapter adapter;
private DataBaseHandler db;
private ListView dataList;
SearchView searchView;
private AdView adView;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auteurs);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
db = new DataBaseHandler(this);
List<Quote> authors = db.getAllAuthors("");
for (Quote cn : authors) {
imageArry.add(cn);
}
adapter = new AuthorsListAdapter(this, R.layout.author_items, imageArry);
dataList = (ListView) findViewById(R.id.listView1);
dataList.setAdapter(adapter);
dataList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
Quote srr = imageArry.get(position);
Intent i = new Intent(getApplicationContext(),
QuotesActivity.class);
i.putExtra("name", srr.getName());
i.putExtra("mode", "isAuthor");
startActivity(i);
}
});

Here it is:
Code:
@override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
Quote srr = imageArry.get(position);
Intent i = new Intent(getApplicationContext(),
QuotesActivity.class);
i.putExtra("name", srr.getName());
i.putExtra("mode", "isAuthor");
startActivity(i);
}
});

cant build apk
Thank you! I made the changes but when i go to build the apk it gives the following errors
error: <identifier> expected
error: <identifier> expected
error: <;> expected
error: <identifier> expected
error: <identifier> expected

nickblu said:
Thank you! I made the changes but when i go to build the apk it gives the following errors
error: <identifier> expected
error: <identifier> expected
error: <;> expected
error: <identifier> expected
error: <identifier> expected
Click to expand...
Click to collapse
looks like errors in your syntax.
I strongly recommend to pick some basics skills in programming, study java and android development, if you really want to make good app by yourself.

Related

[Q] How to modify memory capacity?

Hello guys,
Here is the script to get RAM capacity of a device. It's really different to other device specs that I read.
I have no idea how to hook to change it (memInfo.totalMem) .
PHP:
ActivityManager actManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;
The system file "/proc/meminfo" also holds RAM memory info, I tried to modify this file but didn't affect.
Is there anyway to solve this problem??
Have a nice day.
kidsphy said:
Hello guys,
Here is the script to get RAM capacity of a device. It's really different to other device specs that I read.
I have no idea how to hook to change it (memInfo.totalMem) .
PHP:
ActivityManager actManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;
The system file "/proc/meminfo" also holds RAM memory info, I tried to modify this file but didn't affect.
Is there anyway to solve this problem??
Have a nice day.
Click to expand...
Click to collapse
You can try:
Code:
ActivityManager.MemoryInfo memInfo = (ActivityManager.MemoryInfo) XposedHelpers.newInstance(ActivityManager.MemoryInfo.class);
XposedHelpers.setObjectField(memInfo, "totalMem", 141211211L);
OR:
Code:
Constructor<?> constructLayoutParams = XposedHelpers.findConstructorExact(android.app.ActivityManager.MemoryInfo.class, Parcel.class);
constructLayoutParams.setAccessible(true);
XposedBridge.hookMethod(constructLayoutParams, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.args[0] != null) {
param.args[0] = new CustomMemoryInfo();
}
}});
CustomMemoryInfo extends MemoryInfo class, you can override super method to change "totalMem" attribute
hahalulu said:
You can try:
Code:
ActivityManager.MemoryInfo memInfo = (ActivityManager.MemoryInfo) XposedHelpers.newInstance(ActivityManager.MemoryInfo.class);
XposedHelpers.setObjectField(memInfo, "totalMem", 141211211L);
OR:
Code:
Constructor<?> constructLayoutParams = XposedHelpers.findConstructorExact(android.app.ActivityManager.MemoryInfo.class, Parcel.class);
constructLayoutParams.setAccessible(true);
XposedBridge.hookMethod(constructLayoutParams, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.args[0] != null) {
param.args[0] = new CustomMemoryInfo();
}
}});
CustomMemoryInfo extends MemoryInfo class, you can override super method to change "totalMem" attribute
Click to expand...
Click to collapse
Thank for your reply, but it doesn't work. Have you ever tried running this piece or it's just your thinking?
Here's a commented example of doing this (at least for the method that you posted):
Java:
// Hook the method getMemoryInfo from the ActivityManager class
XposedHelpers.findAndHookMethod(ActivityManager.class, "getMemoryInfo", ActivityManager.MemoryInfo.class, new XC_MethodHook() {
// We use afterHooked here because you have to modify the values *after* the method already setup the object,
// as this method take the object passed as argument and parcel the data (it's always good to check the source)
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ActivityManager.java#2358 > which calls
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ActivityManagerNative.java#4918
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Method contructor -> public void getMemoryInfo(MemoryInfo outInfo)
// As you can see, the getMemoryInfo take a MemoryInfo object as argument
// you just have to get the object from the arguments array, and then cast
// to MemoryInfo to set the desired field
((ActivityManager.MemoryInfo) param.args[0]).totalMem = 12345678L;
((ActivityManager.MemoryInfo) param.args[0]).availMem = 87654321L;
}
});
mauricio_C said:
Here's a commented example of doing this (at least for the method that you posted):
Click to expand...
Click to collapse
Thank you so much :good:

Calling another method from another class

I have hooked a function from a class (w.class) and I want to call another function from another class (x.class). However, this x.class does not have any context or instance.
I tried searching XDA, Google and Github, but couldn't solve my problem. The closest thing I found was https://forum.xda-developers.com/xposed/findclass-returning-java-lang-class-t2853108 but as I stated, I do not have a context or instance.
My w.class is:
PHP:
final class w
extends Thread
{
private Handler b = new Handler();
w(SplashActivity paramSplashActivity) {}
public final void run()
{
this.b.postDelayed(new x(this), 2000L);
super.run();
}
}
and the x.class is
PHP:
final class x
implements Runnable
{
x(w paramw) {}
public final void run()
{
w.a(this.a).startActivity(new Intent(w.a(this.a).getApplicationContext(), pack.class));
}
}
I have hooked the run() function from w.class, but I don't know how to call the run() method from x.class.
My Xposed module looks like this:
PHP:
XposedHelpers.findAndHookMethod("com.pack.w", lpparam.classLoader, "run", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
XposedBridge.log(TAG + " we are replacing... " );
Class<?> classstart = XposedHelpers.findClass("com.pack.x", lpparam.classLoader);
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
XposedHelpers.callMethod(class2Instance, "run");
XposedBridge.log(TAG + " replacing should be done " );
return null;
}
});
but since there is no "context" in x.class, it does not get the object and I cannot use callMethod()
any ideas, please? I am bit stucked
P.S.: Btw, the main goal is to remove the 2000ms wait from "postDelayed()". I did it through .smali already, but wanted to learn how to do it in Xposed.
still nothing?
I feel like this is more complicated than necessary. If Xposed weren't in the picture, and you were writing code that would end up in w.class, what statement would you put there to do what you want?
josephcsible said:
I feel like this is more complicated than necessary. If Xposed weren't in the picture, and you were writing code that would end up in w.class, what statement would you put there to do what you want?
Click to expand...
Click to collapse
Hi and thanks for answering!
I would just write a call to the e.class.
rauleeros said:
Hi and thanks for answering!
I would just write a call to the e.class.
Click to expand...
Click to collapse
I meant can you post the exact line of Java that you'd add, and which method you'd put it in?
josephcsible said:
I meant can you post the exact line of Java that you'd add, and which method you'd put it in?
Click to expand...
Click to collapse
Well, I would simply replace it with this:
PHP:
public final void run()
{
this.b.postDelayed(new x(this), 10L); // run for 10ms instead of 2 seconds
super.run();
}
rauleeros said:
Well, I would simply replace it with this:
PHP:
public final void run()
{
this.b.postDelayed(new x(this), 10L); // run for 10ms instead of 2 seconds
super.run();
}
Click to expand...
Click to collapse
Why are you involving a Context at all? Try this:
Code:
// Replace this:
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
// With this:
Object class2Instance = XposedHelpers.newInstance(classstart, param.thisObject);
josephcsible said:
Why are you involving a Context at all? Try this:
Code:
// Replace this:
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
// With this:
Object class2Instance = XposedHelpers.newInstance(classstart, param.thisObject);
Click to expand...
Click to collapse
Didn't even realize I could do it as simple as that! Thanks a lot for the help, I really appreciate it man

how to change/replace class constants

i have a class like this
PHP:
package com.insight.sdk;
public class ISBuildConfig {
public static int ASSETS_JAR_VERSION_CODE = 100043;
public static String ASSETS_JAR_VERSION_NAME = "v100.1.2.0_release";
public static boolean DEBUG = false;
public static int LOADER_VERSION_CODE = 100043;
public static String LOADER_VERSION_NAME = "v2.1.3_release";
public static final int NOUGAT = 24;
}
i want to change DEBUG to true
how to use xposed to change this value?
hotwap said:
...
how to use xposed to change this value?
Click to expand...
Click to collapse
Try kooking it as early as possible (Application's onCreate() is a good place to do that):
PHP:
XposedHelpers.findAndHookMethod(>>> APPLICATION.class <<<, "onCreate", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.setStaticBooleanField(ISBuildConfig.class, "DEBUG", true);
}
}

Run Java Class With Root Permissions (Not running)

SU Version 2.82 and using BlueStacks 3
I've made a post on StackExchange but w/o any responses - inside are links I'll reference below but unfortunately can't directly post here due to being a new user of these forums. Googling the following should turn up the result: SU Command to start java class for input automation not working
Since then I've learned a bit more about what I'm trying to do (which is surprising considering I've been attempting this since the 30th of January) and implemented a singleton so that I can toast from within the class I'm attempting to start. Regardless of whether this allows me to inject inputs to other apps, my current problem is simply that I'm unable to use a SU command to open up my Main.Java class as described in the following links:
The code describing what I'm trying to do: OmerJerk Execute Java Class as Root User
The code w/ a full implementation: Remotedroid on GitHub
^ ServerService runs MainStarter which runs Main.Java as SU so that Main.Java can run EventInput to inject motion events
The super basic implementation I've got is below, but I've tried a bunch of things. I can't seem to figure out what's going wrong.
A snippet from ActivityMain wherein I'm running the Main.Java (attempting at least):
Code:
new Main().main(COMMAND3); //COMMAND3 is just a String[] because if it's not provided this won't execute. This isn't what I'm trying to do, though. Just a test to see if my Main.Java was broke.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids){
try {
//BlueStacks is 32 bit so it only has app_process - it doesn't have app_process32 and I believe if you try to target it it simply fails (the symbolic link is inconsistent iirc) vv
String[] COMMAND4 = {"su", "-c", "\"CLASSPATH=" + MainActivity.this.getPackageCodePath(), "/system/bin/app_process", "/system/bin", MainActivity.this.getPackageName() + ".Main"};
java.lang.Process console = Runtime.getRuntime().exec(COMMAND4);
BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(console.getOutputStream()));
String outputStr = new String();
BufferedReader reader = new BufferedReader(new InputStreamReader(console.getInputStream()));
while (reader.ready()) {
outputStr += reader.readLine();
}
PropertyReader.getInstance().setText(outputStr);
} catch (IOException e) {
e.printStackTrace();
PropertyReader.getInstance().showToast("IOException" + e.getMessage());
}
// final List<String> SUOutput = Shell.SU.run(String.format(COMMAND,
// new String[] {
// getApplicationContext()
// }));
// final String joined = TextUtils.join(", ", SUOutput);
//
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (SUOutput != null) {
// Toast.makeText(MainActivity.this, "Output isn't null" + joined, Toast.LENGTH_LONG).show();
// Toast.makeText(MainActivity.this, joined, Toast.LENGTH_LONG).show();
// Toast.makeText(MainActivity.this, SUOutput.toString(), Toast.LENGTH_LONG).show();
//
// } else {
// Toast.makeText(MainActivity.this, "Output is null o-o", Toast.LENGTH_LONG).show();
// }
// }
// });
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "It finished.. ?", Toast.LENGTH_LONG).show();
PropertyReader.getInstance().ToastString();
}
});
return null;
}
}.execute();
}
And my Main.Java is reaaaally simple and very stripped down at this point:
Code:
package intsumniac.overbitegames.com.intsumniac;
import android.os.Process;
public class Main {
public static void main(String[] args) {
PropertyReader.getInstance().showToast("Main Is working!!! SUCCESS" + "current process id = " + Process.myPid() + "current process uid = " + Process.myUid()); //Should be 0, preferably
}
}
It is certainly possible to run Java stuff as root, however you are lacking many contexts/instances/etc. There is some trickery to be able to get around some of that. Some of my apps' root parts are mostly Java, in fact.
Rule of thumb is that most Android API calls are not available, just standard Java things. Toasting for example is most certainly not available.

WebApp + sql. Can't make sql to work.

Hey guys.
So, I've spent the last two days watching every tutorial about working with sqlite, but I'm doing something wrong and can't find out what.
The app is done, only needs the SQLite part, Its basicly a webapp with favorites.
Altough I have changed the code several times, this is what I ended up with:
DBManager.java
<code>
package com.rjpf.mywebapps;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public class DBManager
{
private DbHelper dbHelper;
private Context context;
private SQLiteDatabase database;
public DBManager(Context c)
{
context=c;
}
public DBManager open() throws SQLException
{
dbHelper = new DbHelper(context);
database = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
dbHelper.close();
}
public void insert(String name, String url)
{
ContentValues contentValue = new ContentValues();
contentValue.put(DbHelper.CONTACTS_COLUMN_NAME, name);
contentValue.put(DbHelper.CONTACTS_COLUMN_URL, url);
database.insert(dbHelper.CONTACTS_TABLE_NAME, null, contentValue);
}
}
</code>
When I try to call it in the main activity with:
MainActivity.java
<code>
(...)
private LinearLayout Layout_Add;
private TextView TxT_add_nomE;
private TextView TxT_add_urL;
private Button Button_Add_to_DB;
private Button btn_BACK_Add;
DbHelper myDB;
(...)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myDB = new DbHelper(this);
(...)
Button_Add_to_DB.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
Add_ItemToDb();
}
});
(...)
public void Add_ItemToDb()
{
if (TxT_add_nomE.getText().toString().trim().length() == 0 || TxT_add_urL.getText().toString().trim().length() == 0)
{
TxT_add_nomE.setText("Please don't leave fields empty!");
return;
}
else
{
String addNome = TxT_add_nomE.getText().toString();
String addUrl = TxT_add_urL.getText().toString();
// ADD TO DB
DBManager DataManager = new DBManager(this);
DataManager.insert(addNome,addUrl); // This line is what gives the error, when I click the button to add the App craches
TxT_add_nomE.setText("Name");
TxT_add_urL.setText("Url");
}
}
</code>
Thanks in advance and sorry for the long post, This is my first app and also the first time in java

Categories

Resources