Hi there,
I'm working on my LeoParts and integrated ROM Updater in my ROM.
Now I want my LeoParts to launch ROM Updater on a PreferenceScreen.
I tried two things:
1. With the XML
Code:
<PreferenceScreen
android:key="rom_update"
android:title="@string/updates_title"
android:summary="@string/updates_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="org.elegosproject.romupdater"
android:targetClass="org.elegosproject.romupdater.VersionsList"/>
</PreferenceScreen>
2. With the Java code
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("org.elegosproject.romupdater", "org.elegosproject.romupdater.VersionsList");
startActivity(intent);
3. From the shell
Code:
am start -a android.intent.action.MAIN -n org.elegosproject.romupdater/.VersionsList
This last one works, but I would like something less hacky...
Here is the error I get from a logcat:
Code:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=org.elegosproject.romupdater/.VersionsList } from ProcessRecord{407e1ed8 775:com.leonnib4.leo_parts/10044} (pid=775, uid=10044) requires null
I know this as something to do with permissions, most likely in the AndroidManifest.xml, but I can't get it to work.
Please help me out
Thx
I got arround by doing:
Code:
Intent intent = getPackageManager().getLaunchIntentForPackage("org.elegosproject.romupdater");
if (intent != null) {
toast.show();
String commands[] = {
"am start -a android.intent.action.MAIN -n org.elegosproject.romupdater/.VersionsList"
};
// Execute in a shell
} else {
// Toast notif "ROM Updater is missing"
}
But that is still hacky and I'm still looking for a better way to do this...
Thx
Related
Im trying to run a su command from within a hook,
Code:
Process p;
try {
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
toastMessage("root");
return true;
} else {
toastMessage("not root");
}
} catch (InterruptedException e) {
toastMessage("not root");
}
} catch (IOException e) {
toastMessage("not root");
}
But even though I grant the shell su access I still get error:
tmp-mksh: <stdin>[1]: can't create /system/sd/temporary.txt Read-only file system
Any ideas?
mount system as rw?
Ty, I'll give it a shot. Could be Selinux related too but no errors other than in su log. Might need to post this to root section. Not really a problem with the hook I don't think.
hello,
does anyone here can get over this problem :
i'm one lollipop and can't enter the API menu to sim unlock ,and this's what i get
D:\Mobiles\HTC\HTC M\abd>adb shell
[email protected]_m8whl:/ $ su
su
[email protected]_m8whl:/ # am start com.redbend.vdmc/com.htc.omadm.test.TestMainActivity
rt com.redbend.vdmc/com.htc.omadm.test.TestMainActivity <
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.L
AUNCHER] cmp=com.redbend.vdmc/com.htc.omadm.test.TestMainActivity }
Error type 3
Error: Activity class {com.redbend.vdmc/com.htc.omadm.test.TestMainActivity} doe
s not exist.
[email protected]_m8whl:/ #
i guess i need a new version of HtcOMADM_SPCS that's is compatible with lollipop
thanks
I have inported an Eclipse app into Studio. When I run the app I get the fatal error:
Attempt to invoke virtual method 'void android.nfc.NfcAdapter.enableForegroundDispatch(android.app.Activity, android.app.PendingIntent, android.content.IntentFilter[ ], java.lang.String[ ][ ])' on a null object reference
As far as I can tell the error is caused by the mAdapter.enableForegroundDispatch method below, because one ore more of it's parameters is null. I put a breakpoint there and run the debugger in the emulator. It never hits the breakpoint. I also set the debugger to break on any exception and it doesn't. the App starts and I get the "unfortunately the app has stopped" message.
@override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
//Used for DEBUG : Log.v("NFCappsActivity.java", "ON RESUME NFC APPS ACTIVITY");
mPendingIntent = PendingIntent.getActivity(this, 0,new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
}
Thanks for the help.
Rich
Hey, I'm fairly new to using android studios and I am trying to make an app that updates its display every few seconds.
The method I am currently using is to update when a button is pressed using the following:
public void Refreshing(View view) {
// do stuff here...
}
Where Refreshing is the onClick of a button I placed.
How can I use a similar format but instead of doing things on a button press just have it done automatically after a few seconds?
You can use a android.os.Handler for that. It allows you to interact with the event loop and post a Runnable that will be executed after a given delay
In your Activity's onCreate() method:
Code:
final int delayMs = 1000;
final Handler handler = new Handler(this);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed(runnable, delayMs);
};
}
handler.postDelayed(runnable, delayMs);
Thanks, this is exactly what I'm looking for. I add the code to the onCreate but I had an semicolon error. So I added another semicolon but its having trouble with a few other parts. Here is what I have.
Code:
final int delayMs = 1000;
final Handler handler = new Handler([B]this[/B]);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed([B]runnable[/B], delayMs);
};
};
handler.postDelayed(runnable, delayMs);
The error listed is:
Error : (134, 33) error: no suitable constructor found for Handler(MainActivity)
constructor Handler.Handler(Looper,Callback) is not applicable
(actual and formal argument lists differ in length)
constructor Handler.Handler(Looper) is not applicable
(actual argument MainActivity cannot be converted to Looper by method invocation conversion)
constructor Handler.Handler(Callback) is not applicable
(actual argument MainActivity cannot be converted to Callback by method invocation conversion)
constructor Handler.Handler() is not applicable
(actual and formal argument lists differ in length)
The words I bolded are underlined in red in Android Studios.
this ----------------has a constructor error
runnable ----------has a initialization error
I tried troubleshooting for a little bit and took out the this and the only error left is with runnable. It says: Error: (141, 37) error: variable runnable might not have been initialized
Yep, I wrote the code without testing it. It might need some adaptation.
Here is a version that should work:
Code:
final int delayMs = 1000;
final Handler handler = new Handler([B]this[/B]);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed([B]this[/B], delayMs);
};
};
handler.postDelayed([B]runnable[/B], delayMs);
Thank you so much, it worked. I just had to change
Code:
final Handler handler = new Handler(this);
to
Code:
final Handler handler = new Handler();
First of all, we need to reboot the device by button click.
Device: Mediatek MT6737M Android 6.0 running Marshmallow
I currently have three devices. One rooted with Magisk another SuperSU the third with Kingroot. In the settings on all three root managers I have it set to grant all permissions. When we try and restart Kingroot flashes a prompt to allow permission which we can work around but Kingroot is riddled with garbage that we don't want. We want to use Magisk or SuperSU because they are clean with less baggage. Magisk and SuperSU however throw an error: java.io.IOException:
Code:
Error running exec(). Command: [/system/bin/su, -c, reboot now] Working Directory: null Environment: null.
This is the code we're using to access PowerManager:
Code:
void reboot() {
if (reboot) {
try {
Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/su", "-c", "reboot"});
proc.waitFor();
} catch (Exception ex) {
Log.e(TAG, "Error ", ex);
}
}
}
Is there a way to grant permission to this process using either Magisk or SuperSU? If not is there another rooting management tool or software that is clean and malware free that can achieve that?
NOTE: Code by senior developer I am a Baby, Jr dev here tasked with finding the answer. Please be patient if I ask dumb questions.
Ok so first thing I'll start by saying that you should be making su calls in a background thread. The su call is a blocking call so it will block the UI thread which can cause ANRs (crashes) and overall bad user experience. AsyncTask is perfect for su calls to run in the background instead.
You should also stick with Magisk as it is actively being developed and is the current standard.
Let's get started. Create a new class and call it RootShell.java. Then copy the following code into it.
Java:
class RootShell {
private static void exec(String[] cmd) {
new Execute().execute(cmd);
}
private static class Execute extends AsyncTask<String, Void, Void> {
Override
protected Void doInBackground(String... cmds) {
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd + "\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}
Keep in mind that XDA has awful code formatting so the Override should have the @ symbol in front of it.
Now you can pass single or multiple root commands to this class which will be executed in a background thread. Here's how...
Lets say you're using a button in another class to reboot the phone. This is what it would look like...
Java:
private void rebootButton(View view) {
String[] cmd = { "reboot" };
RootShell.exec(cmd);
}
To pass multiple commands your button would look like this.
This is to reboot into safe mode...
Java:
private void rebootSafeMode(View view) {
String[] cmd = {
"setprop persist.sys.safemode 1",
"setprop ctl.restart zygote"
};
RootShell.exec(cmd);
}
For more info on how to properly su you should check out the following link...
https://su.chainfire.eu/
Hope this helps you with your app and good luck.