1
㈡有一个代码,以从其他应用程序,代码工作以及打开计算器,但我更改包名来打开不同的应用程序无法正常工作机器人工作室不容打开其他应用
有谁知道我不得不改变
package com.example.zeluis.c4;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class c4 extends AppCompatActivity {
// aki comesa abrir os app
private String packge_name = "com.android.calculator2";
private String class_name = "com.android.calculator2.Calculator";
private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c4);
bt = (Button) findViewById(R.id.but);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
launchCall();
}
});
}
protected void launchCall() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packge_name, class_name));
try {
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
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_c4, 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);
}
}
我的想法是更改包名称来打开另一个应用程序,如whatapp或Navfree .etc
我不确定确切的问题是什么,你是说'launchCall()'不工作?如果是这样,请展示它的功能。 –
你已经提供了一切,但我们实际需要看到的代码位... –
现在我过去了所有的代码。此代码工作,但我想打开其他应用程序不是计算器我不能 –