我有一个应用程序应该使用一些shell命令将文件从SD卡复制到/ system/media /.它将需要root,我正在root设备上进行测试.我正在使用运行时来执行shell命令,但它不起作用.这是我的运行时间
public void RunAsRoot{String[] commands = {"sysrw", "rm /data/local/bootanimation.zip", "sysro"};{
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for (String tmpCmd : commands) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
}
Run Code Online (Sandbox Code Playgroud)
但我的logcat只显示其中两个没有被拒绝
07-30 03:14:11.112: WARN/su(3593): request rejected (10047->0 /system/bin/sh)
07-30 03:14:11.132: DEBUG/su(3592): 10047 com.bba.stormdroid executing 0 /system/bin/sh using shell /system/bin/sh : sh
07-30 03:14:11.152: WARN/su(3594): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.182: WARN/su(3595): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.202: WARN/su(3596): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.242: DEBUG/su(3597): 10047 com.bba.stormdroid executing …Run Code Online (Sandbox Code Playgroud) 我有一个RealmResults<Section>,有一个RealmList<Event>是我想清楚每一节现场.
我试过了(insude mRealm.executeTransaction)
for (Section section : mSections) {
section.getEvents().clear();
}
Run Code Online (Sandbox Code Playgroud)
和
Iterator<Section> sectionIterator = mSections.iterator();
while (sectionIterator.hasNext()) {
sectionIterator.next().getEvents().clear();
}
Run Code Online (Sandbox Code Playgroud)
但是Realm抛出了这个例外
java.util.ConcurrentModificationException:迭代RealmResults时不允许对Realm进行外部更改.请改用迭代器方法.
我有一个1x20px的ImageView.图像是.9.png.我正在尝试使用match_parent但是当我在我的设备上运行应用程序时,它没有被拉伸以填充屏幕的宽度.这是ImageView的XML代码
<ImageView
android:id="@+id/dividerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_bar"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside" />
Run Code Online (Sandbox Code Playgroud)
关于如何让ImageView覆盖整个屏幕宽度的任何想法?
我正在创建一个应用程序,我想从菜单中启动一个新活动,但是当我单击菜单按钮时,应用程序崩溃了.我尝试了很多方法,所有方法都失败了.
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(getApplication())
.inflate(R.menu.menu, menu);
return(super.onPrepareOptionsMenu(menu));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.Menu1:
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
break;
case R.id.Menu2:
Intent Intent = new Intent(this, About.class);
startActivity(Intent);
}
return(super.onOptionsItemSelected(item));
}
}
Run Code Online (Sandbox Code Playgroud)
Android Manifest
Run Code Online (Sandbox Code Playgroud)<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".AndroidRssReader" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".About" android:label="@string/app_label"></activity>